design - Designing Javascript validation methods -


When validation is done in JavaScript, how do I keep verification procedures which can be used to combat a bunch of contingencies Need it?

For example, I have a form with that field which has the verification:

  • Is there a new value?
  • Is the value in the second field on the form> 0 when the current field> 0
  • is another field on the forest == 1 and the current field == 0
  • There is another field on the form == true and any other field is modified in the current field == 0

etc.

Currently, I have a / if the bunch of statements. / P>

I can test it in my own method and break each and call it through the main verification method, but this will create a new technique.

Updates : Whether I use a framework or personal methods, am I still resigning to resign with the eligibility method to call / or fail in other assumptions?

Looks like you want a native state machine The one thing you can consider is the simplest The forms are breaking the validator:

  function validator (op, option, pass, unsuccessful) {if (op (option)) {pass (option); } Else {unsuccessful (option); }}  

Then you can combine them together to create more complex systems

  function foo checked (option) {return dollar (options. Foo) .This (': check'); } Function is called (option) {alerts ('hi' options.name); } Function failed (option) {warning (options.name + 'was bad'); } Function validName () {validator (isFooChecked, {foo: '#somefield', name: $ ('# nameField'). Val ()}, sayHi, fail); }  

You still have many codes, but if you correct it, the function should be small and easy to understand.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -