Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Input validation

$
0
0
Use the can.map.validations plugin.  Then in each model class's init() method you can declaratively set the validations with this.validate(), this.validatePresenceOf(), this.validateFormatOf(), etc.

What we do is to set up a compute around each instance's errors() method (which is provided by the validations plugin), and call it computed_errors.  Then you can simply do:
  1. {{#if computed_errors.<name of some validated attr>}}<label class="error">Error message</label>{{/if}}
 in your mustache.

Note that errors() returns null if there are no validation errors, so it's very useful for disabling the submit button in your form.

Viewing all articles
Browse latest Browse all 3491

Trending Articles