Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery validation , when input field has a title attribute , instead of error message title is given as the error message

hi i am using jquery validation plugin .

i have a strange issue , i have a validaion like this

jQuery("#profile_info").validate({

    rules : {
        city : {
            required : true,
            minlength : 3,
            maxlength : 30,
            cityvalidation: true
        },
        state : {
            required : true,
            minlength : 3,
            maxlength : 30,
            cityvalidation: true
        }
    },
    messages : {
        city : {
            required : " City must be  filled in",
            minlength : "At least 3 characters long",
            maxlength : "Should not exceed 30 characters",
        },
        state : {
            required : " State must be  filled in",
            minlength : "At least 3 characters long",
            maxlength : "Should not exceed 30 characters",
        }
    }
});

and cityvalidation

jQuery.validator.addMethod("cityvalidation", function(value, element) {
      return this.optional(element) || /^[a-zA-Z\u0080-\u024F\s\/\-\)\(\`\.\"\']+$/i.test(jQuery.trim(value));
    }, "You Have Typed Unallowed Charactors");

my input fields are

                                                    <div class="select-date-container-side location-codes">
                                                        <input id="city" name="city"
                                                            value="<?php if(isset($profileinfo['CityName'])){echo $profileinfo['CityName'];}else if(isset($city)){echo $city;} ?>"
                                                            title="City" type="text"
                                                            class="smaler-textfield textfield clear-default"
                                                            tabindex="1900" />
                                                    </div>
                                                    <div class="select-date-container-middle location-codes">
                                                        <input id="state" name="state"
                                                            value="<?php if(isset($profileinfo['StateName'])){echo $profileinfo['StateName'];}else if(isset($state)){echo $state;} ?>"
                                                            title="State" type="text"
                                                            class="smaler-textfield textfield clear-default"
                                                            tabindex="1900" />
                                                    </div>

if the cityvalidation failed . "You Have Typed Unallowed Charactors" message , but instead of that the titles of the fields are shown .

enter image description here

  • if i remove the title it works perfectly . so what i suppoesed to do . i want to get the custom error message instead of title . please help........

thanks in advance .....................

like image 530
Kanishka Panamaldeniya Avatar asked Apr 24 '12 06:04

Kanishka Panamaldeniya


1 Answers

hmmm i found it .

i used ignoreTitle: true,

jQuery("#profile_info").validate({


    ignoreTitle: true,

    rules : {
        city : {
            required : true,
            minlength : 3,
            maxlength : 30,
            cityvalidation: true
        },
        state : {
            required : true,
            minlength : 3,
            maxlength : 30,
            cityvalidation: true
        }
    },
    messages : {
        city : {
            required : " City must be  filled in",
            minlength : "At least 3 characters long",
            maxlength : "Should not exceed 30 characters",
        },
        state : {
            required : " State must be  filled in",
            minlength : "At least 3 characters long",
            maxlength : "Should not exceed 30 characters",
        }
    }
});
like image 54
Kanishka Panamaldeniya Avatar answered Nov 16 '22 15:11

Kanishka Panamaldeniya