Reputation: 6004
I am using jquery validator, the input field left as blank and showing its value as empty, but jquery valid() method is always returning true. Actually there are several tabs inside the form, and each click of next the next tab will be shown and previous will be hidden. So we cant validate all the form at once My validation rule is given as:
$('#wizard_example_1').validate({
rules: {
link_client_name: {
required: true
},
link_page_url: {
required: true,
url: true
},
link_title: {
required: true
},
link_message: {
required: true
},
link_text: {
required: true
},
link_url: {
required: true,
url: true
}
}
});
and the jquery code to check the elements specificaly if they are valid or not is as
$('.next-btn').on('click', function (e) {
e.preventDefault();
count++;
if (obj['camp_type'] === "1") {
var valid = false;
$.each($('#link input'), function (i, v) {
var id=$(this).attr('name');
valid=$('input[name="' + $(this).attr('name') + '"]').valid();
});
if(valid) {
obj = {};
obj['camp_type'] = "1";
obj['client_name'] = $('#link_client_name').val();
obj['page_url'] = $('#link_page_url').val();
obj['title'] = $('#link_title').val();
obj['message'] = $('#link_message').val();
obj['action_text'] = $('#link_text').val();
obj['action_url'] = $('#link_action_url').val();
console.log(obj);
}else{
return false;
}
}
});
Upvotes: 1
Views: 1289
Reputation: 140
Try to Implement with this method.
var $ValidateForm = $('#wizard_example_1').validate({
rules: {
link_client_name: {
required: true
},
link_page_url: {
required: true,
url: true
},
link_title: {
required: true
},
link_message: {
required: true
},
link_text: {
required: true
},
link_url: {
required: true,
url: true
}
}
});
$('.next-btn').off();
$(document).on('click', '.next-btn', function () {
if ($ValidateForm.form()) {
// your logic
}
});
Upvotes: 3