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

Re : Input validation

$
0
0
This is probably not going to be helpful, but I wanted to start to write down my thoughts on validation because I'd like to make a nice validation plugin for 2.2 using 2.1's custom attributes.

I'm very split on the best way to do validation.  In an ideal world, validations would be driven by the model layer similar to how air_hadoken suggested.  This is ideal because most of the time, validations are strongly associated with data which is modeled by can.Map.

However, validations can be presented in a large variety of ways and sometimes validations exist only temporary and would not be associated with a model.  Finally, it's likely we want "composite" validations on things like getter / setter computes.


So, I think there should be two layers of validations.  One layer is pure DOM based.  Similar to HTML5 pattern, required, size, max, min, and maxlength attributes: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input

These would probably need to add observables to the Scope.  For example:


<input can-validate-required name="age"/>
{{#validate.age.failing}}{{#validate.age.errors}}{{/validate.age.failing}}

Then, if someone is using can-validate and can-value, we will read from the map and hook the same kind of thing up:

<input can-validate can-value="person.age"/>
{{person.age.errors}}{{#person.age.errors}}{{/person.age.failing}}


Let me know if anyone is interested in exploring such a plugin.  I can provide guidance on how to make it work.






<input can-value="name" validate-required validate-length-gt="3" />



Viewing all articles
Browse latest Browse all 3491

Trending Articles