SHARE
TWEET

Untitled

a guest Apr 27th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // The following Forms block of stuff is generated on load and included inline at the top
  2. var Forms = Forms || { };
  3. Forms.signupForm = { };
  4. Forms.signupForm.username = [ { name: 'Zend_Validate_Alnum', parameters: { allowWhiteSpace: false }  }, { name: 'Zend_Validate_StringLength', parameters: { min: 3, max: 50 }  } ];
  5. Forms.signupForm.password = [ { name: 'My_Validate_PasswordConfirmation', parameters: {} } ];
  6. Forms.signupForm.email = [ { name: 'Zend_Validate_EmailAddress', parameters: {} } ];
  7. Forms.signupForm.age = [ { name: 'Zend_Validate_Digits', parameters: {} }, { name: 'Zend_Validate_GreaterThan', parameters: { min: 12 }  } ];
  8.  
  9.  
  10. // The below code is in my js/Validator.js
  11. var App = App || { };
  12.  
  13. App.validate = function(form)
  14. {
  15.     var c = form.elements;
  16.     var formName = (form.name)
  17.                  ? form.name
  18.                  : 'form';
  19.  
  20.     var rules = Forms[formName];
  21.     var formValidates = true;
  22.    
  23.     $H(rules).each(function(ruleset){
  24.         var element = $(form[ruleset.key]);  
  25.          
  26.           $H(ruleset.value).each(function(rule) {
  27.               var validatorName = rule.value.name;
  28.               var parameters = rule.value.parameters;
  29.               var value = element.value;
  30.              
  31.               var elementValidates = App.Validator[validatorName](value, parameters);
  32.        
  33.               if (elementValidates) {
  34.                 element.removeClassName('invalid');
  35.               } else {
  36.                 element.addClassName('invalid');
  37.                   formValidates = false;
  38.                 }
  39.             }
  40.         );
  41.       }
  42.     );
  43.        
  44.     return formValidates;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top