For a schema that’s defined a slug, and on submit the slug has been set to an autoValue og slugifying the title. Is there some way to add this behaviour to the actual form submitting process instead? Eg. an input field being automatically filled with a value based off of input in the title field?
For those who are wondering how this can be solved easily, in my case where I wanted slugs automated but editable, the easiest thing to do is just not use autoValue (since this happens server-side) and rather just use Meteors handy keyup
, keydown
or keypress
events and bind it to changes for the field you want to base the slug off of and then just set the value to the field you want slugified, as such:
Template.showSubmit.events({
"keyup #showSubmit input[name=name]": function(e, template) {
// slugify name
var nameValue = $('[name=name]').val().toLowerCase();
var slug = _.slugify(nameValue);
// set default slug
$('[name=slug]').val(slug);
}
});
1 Like
Thanks for posting the follow-up!
1 Like