Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Defaults stopped working #1566

Closed
attiqeurrehman opened this issue Sep 1, 2015 · 6 comments
Closed

Set Defaults stopped working #1566

attiqeurrehman opened this issue Sep 1, 2015 · 6 comments

Comments

@attiqeurrehman
Copy link

Hi,

I have recently did an upgrade of jQuery and jQuery Validation to the latest version of both. But this caused my defaults to stop working(validation is working) on some pages even though all pages share the same master page (where code is placed).

Here's the code:

$.validator.setDefaults({
                    highlight: function (element) {
                        console.log('highlight');
                        $(element).closest('.form-group').addClass('has-error');
                    },
                    unhighlight: function (element) {
                        console.log('unhighlight');
                        $(element).closest('.form-group').removeClass('has-error');
                    },
                    errorElement: 'span',
                    errorClass: 'help-block',
                    errorPlacement: function (error, element) {
                        console.log('errorPlacement');
                        if (element.parent('.input-group').length) {
                            error.insertAfter(element.parent());
                        } else {
                            if ($(element).parent().prop("tagName") == "LI") {
                                error.insertAfter(element.parent().parent());
                            } else if ($(element).next().next().prop("tagName") == "SPAN") {
                                error.insertAfter($(element).next().next());
                            } else {
                                error.insertAfter(element);
                            }
                        }
                    }
                });

It goes into the plugin code but defaults are not set. Any pointers as to where can I look?

Thanks,
Attiqe
@staabm
Copy link
Member

staabm commented Sep 1, 2015

May I guess that you are using the updated jQuery version in noConflict mode?

Could you please tell us exactly which versions of both libs you are using? Any errors? Which version worked correctly before?

@attiqeurrehman
Copy link
Author

I am using jQuery v 2.1.4 and jQuery Validation v 1.14.0, no error and previously I used jQuery 2.0.3 and jQuery Validation 1.13.1.

But latest libraries are working on jsfiddle. I have also tried to debug it, Here's my findings:

// http://jqueryvalidation.org/jQuery.validator.setDefaults/
setDefaults: function( settings ) {
    $.extend( $.validator.defaults, settings );
}

At this point here is the $.validator.defaults
validator defaults

and settings are

settings

after extending them $.extend it becomes

validator defaults with my settings

this means that it have picked up my settings but it's not applying it(here's the generated html after validating):

<div class="form-group">
       <label class="col-sm-5 control-label">Experience <small>(in years) </small></label>
       <div class="col-sm-7">
            <input name="ctl00$ContentPlaceHolder1$EmployeeSkillExperience" type="text" maxlength="4" id="ctl00_ContentPlaceHolder1_EmployeeSkillExperience" class="form-control error" required="required" aria-required="true" aria-invalid="true">
            <label id="ctl00_ContentPlaceHolder1_EmployeeSkillExperience-error" class="error" for="ctl00_ContentPlaceHolder1_EmployeeSkillExperience">This field is required.</label>
       </div>
</div>

It should have been like this:

<div class="form-group has-error">
       <label class="col-sm-5 control-label">Experience <small>(in years) </small></label>
       <div class="col-sm-7">
              <input name="ctl00$ContentPlaceHolder1$EmployeeSkillExperience" type="text" maxlength="4" id="ctl00_ContentPlaceHolder1_EmployeeSkillExperience" class="form-control" required="required" aria-required="true" aria-describedby="ctl00_ContentPlaceHolder1_EmployeeSkillExperience-error" aria-invalid="true">
             <span id="ctl00_ContentPlaceHolder1_EmployeeSkillExperience-error" class="help-block">This field is required.</span>
         </div>
</div>

@staabm
Copy link
Member

staabm commented Sep 4, 2015

Did you make sure that the lib is not loaded twice?

@attiqeurrehman
Copy link
Author

I am not sure how to check it. I have only wrote them onetime.

On Fri, Sep 4, 2015 at 11:04 PM, Markus Staab notifications@github.com
wrote:

Did you make sure that the lib is not loaded twice?


Reply to this email directly or view it on GitHub
#1566 (comment)
.

Attiqe Ur Rehman

@staabm
Copy link
Member

staabm commented Oct 21, 2015

@attiqeurrehman any news? Did you found the cause of the issue?

@staabm
Copy link
Member

staabm commented Feb 5, 2016

Closing because no more feedback

@staabm staabm closed this as completed Feb 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants