Sviatlana
Sviatlana

Reputation: 1888

Jquery valid() always returns true

I am usind jquery validator to perform validation of my form. This is validator and its call:

$(document).ready(function() {
    $("#search_form").validate({
        rules:{
            templateName:{
                required: true,
            },
        },
        errorElement: "div"
    });

  $('#templateConfirmDialog').on('show.bs.modal', function (event) {
    $(this).find('.modal-yes').click(function(){
        $("#search_form").validate();
        if($("#search_form").valid()){
            alert('aaa');
        }
    })
  })

});

This is element for validation:

<input name="createTemplate.templateName" type="text" id="templateName" class="ui-widget-content ui-corner-all сriteria"/>

Debugger goes into click() function. If I call $("#search_form").validate() in the console, I see right parameters of my validator, but error list is empty (in case I entered nothing into attribute wit id=templateName). What is the mistake?

Upvotes: 0

Views: 429

Answers (1)

Anirudha Gupta
Anirudha Gupta

Reputation: 9279

Replace your code

<input name="createTemplate.templateName" type="text" id="templateName" class="ui-widget-content ui-corner-all сriteria"/>

to

<input type="text" name="templateName" class="ui-widget-content ui-corner-all сriteria"/>

If your code need to have same name attribute as you have in your question then try quoting your name in single quotes.

Upvotes: 1

Related Questions