jQuery Validator don`t work correctly -


i have simple form validate user has enter project name. if current action "create" have check if entered value in database , return error message. if it`s edit have check if entered value different current value , in situation check again if new in database. code here:

if (((action_current == action_edit) && ($(id).val() != projectdata.project.name)) || (action_current ==  action_create)) {             initprojectnamevalidator();         }          if ($(id).valid()) {             return true;         } else {             return false;         }   function initprojectnamevalidator() {     jquery.validator.addmethod('checkduplicatename', function(value) {         var isinarray = $.inarray(value, projectsnames);         return (isinarray == -1);     }, messages.duplicateproject);      $('#editprojectdialogform').validate({         rules : {             projectform_name : {                 required : true,                 checkduplicatename : true             }         }     }); } 

at first look, works fine. there's problem when action "edit". if have projects (aaa, bbb, ccc) , go project "aaa" , try change "bbb" returns error message. if go project "aaa" , try change "aaa" doesn't return error message. here comes problem. if go project "aaa" try change "aaa" there's no problem, if without refresh try after change "bbb" there's no error message, here have error message. same happen if try change "aaa" "bbb" - give error , if without refresh try change "aaa" there's error again there shouldn't be

your question unclear , seems of relevant code missing. however, there 1 obvious error...

your logic flawed. trying use .valid() method before calling .validate() method.

.validate() used initialize plugin on form , must called first. after it's initialized, can programmatically trigger validation calling .valid() method.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -