jQuery Validation: $.data($('form')[0], 'validator').settings returns undefined

前端 未结 5 623
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 22:35

I have an ASP.Net MVC Project and I am using unobtrusive jQuery Validation. to add validation when an element loses focus, I am calling

$(document).ready(function         


        
5条回答
  •  清酒与你
    2021-02-05 22:51

    Looks like your projects use different types of validadion (One of them use unobtrusive and second use default).

    Please check if you are using next settings in web.config's of both projects.:

        
              
                
            
      
    
    

    Also you are trying to work with first form in your document.

    In case when there is no forms - you will get error.

    In case when there are more then one form - only first form will use focusout for validation.

    So you should do same thing for each form:

    $(document).ready(function () {
        var $forms = $('form');
        $.each($forms, function (key, value) {
            // enable validation when an input loses focus.
            var settings = $.data(value, 'validator').settings;
            settings.onfocusout = function (element) { $(element).valid(); };
        });
    });
    

提交回复
热议问题