Automatic slug field in MeteorJS Meteor JS 09.01.2016

Our test model with schema (in coffeescript)

@Rubric = new Mongo.Collection('Rubric')
RubricScheme = new SimpleSchema
    title:
        type: String
        label: "Ttitle"
        max: 250
    slug:
        type: String
        label: "Slug"
        max: 250
Rubric.attachSchema(RubricScheme)

We need external package meteor-slugify

meteor add yasaricli:slugify

Usage

slugify('some string'); // returns some-string
slugify('тестовая строка'); // returns testovaya-stroka

The package has char map and can transforms cyrillic chars too.

Following is template helper that automatic transforms chars from title field to slug one.

Template.rubricCreate.events
    "keyup input[name=title]": (e, template) ->
        title = $('[name=title]').val().toLowerCase()
        slug = slugify(title)
        $('[name=slug]').val(slug)