javascript - valid() method of jquery validator is always returning true -
i using jquery validator, input field left blank , showing value empty, jquery valid() method returning true. there several tabs inside form, , each click of next next tab shown , previous hidden. cant validate form @ once validation rule 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 jquery code check elements specificaly if valid or not 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; } } });
try implement 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()) { // logic } });
Comments
Post a Comment