lundi 1 février 2021

Dynamic Output for jquery.validator.addMethod

jQuery.validator.addMethod("usersValidator", function(userGroupVal,
            element) {
        
        var userGroupNosVal = $('#userNames').val();
        var pattern = /[]{}]/g;
        var user_group = userGroupNosVal.split(/[ /\n/ " "]+/);
        var wrong_group = [];
             for(var i  = 0 ; i < user_group.length ; i++)
                 {
                      if(user_group[i].match(pattern))
                         {
                          wrong_group.push(user_group[i]);
                         }
                  }
             
                      
            if(userGroupVal == "" || userGroupNosVal == null)
            {
            return true;
            }
            if(wrong_group.length != 0)
            {
            return false;
            }
            else
            {
            return true;
            }
            }
 
     
            , function(param,element)
            {
return  " Users {" + wrong_group + "} cannot contain  these symbols   { } [ ]  " ;
}
);

I have created this jquery validator, I have to display the dynamic error message but right now the message is not displayed because the scope of "wrong_group" is not within the last function which is returning the string(the error message). Can someone please help me with this problem, where should I declare the wrong_group so that I can access it in the message? Except the value of "wrong_group" everything is working fine. Only the value of "wrong_group" is missing.




Aucun commentaire:

Enregistrer un commentaire