Hi, I am using the Phatfusion validation to validate my form. I am trying to get a field to be require field only if a certain drop down selection is selected. I also want this field (number only) to validate be at less value of 25. I have the below script but it will not work. Please Help. Thanks.
Code:var Validate = new Class({ getOptions: function(){ return { validateOnBlur: false, errorClass: 'error', errorMsgClass: 'errorMessage', dateFormat: 'mm/dd/yy', onFail: Class.empty, onSuccess: false, showErrorsInline: true, label: 'Please wait...' }; }, initialize: function(form, options){ this.setOptions(this.getOptions(), options); this.form = $(form); this.elements = this.form.getElements('.required'); this.list = []; this.elements.each(function(el,i){ if(this.options.validateOnBlur){ el.addEvent('blur', this.validate.bind(this, el)); } }.bind(this)); this.form.addEvent('submit', function(e){ var event = new Event(e); var doSubmit = true; this.elements.each(function(el,i){ if(! this.validate(el)){ event.stop(); doSubmit = false this.list.include(el); }else{ this.list.remove(el); } }.bind(this)); if(doSubmit){ if(this.options.onSuccess){ event.stop(); this.options.onSuccess(this.form); }else{ this.form.getElement('input[type=submit]').setProperty('value',this.options.label); } }else{ this.options.onFail(this.getList()); } }.bind(this)); }, getList: function(){ var list = new Element('ul'); this.list.each(function(el,i){ if(el.title != ''){ var li = new Element('li').injectInside(list); new Element('label').setProperty('for', el.id).setText(el.title).injectInside(li); } }); return list; }, validate: function(el){ var valid = true; this.clearMsg(el); switch(el.type){ case 'text': case 'textarea': case 'select-one': if(el.value != ''){ if(el.hasClass('email')){ var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/; if(el.value.toUpperCase().match(regEmail)){ valid = true; }else{ valid = false; this.setMsg(el, ''); } } if(el.hasClass('amt')){ if(amt<=25){ valid = true; }else{ valid = false; this.setMsg(el, ''); } }


Reply With Quote
Bookmarks