Tôi gặp sự cố khi xác thực hộp thoại Giao diện người dùng jQuery bằng cách sử dụng Jquery Validate khi nhấp vào Lưu.Hộp thoại giao diện người dùng jQuery + Xác thực
Đây là mã của tôi để tạo hộp thoại Jquery. Nó tải hộp thoại từ một mục tiêu URL href:
$(document).ready(dialogForms);
function dialogForms() {
$('a.dialog-form').click(function() {
var a = $(this);
$.get(a.attr('href'),function(resp){
var dialog = $('<div>').attr('id','formDialog').html($(resp).find('form:first').parent('div').html());
$('body').append(dialog);
dialog.find(':submit').hide();
dialog.find('#return').hide();
dialog.dialog({
title: a.attr('title') ? a.attr('title') : '',
modal: true,
buttons: {
'Save': function() {submitFormWithAjax($(this).find('form'));},
'Cancel': function() {$(this).dialog('close');}
},
close: function() {$(this).remove();},
width: 'auto'
});
}, 'html');
return false;
});
}
function submitFormWithAjax(form) {
form = $(form);
$.ajax({
beforeSend: function(data) {
//alert("beforesend");
form.validate();
},
url: form.attr('action'),
data: form.serialize(),
type: (form.attr('method')),
dataType: 'text',
error: function(data) {
alert(data);
$('#result').html(data);
},
success: function(data) {
//alert("success");
$('#result').html(data);
setTimeout("reloadPage()", 500);
}
});
return false;
}
Các beforeSend
được gọi, nhưng nó dường như không gọi phương thức validate
, được đặt trên trang mẹ từ đó được gọi là Dialog.
$(document).ready(function() {
$("#event_form").validate({
rules: {
Name: {
required: true
},
Category: {
required: true
}
},
messages: {
Name: "Please enter an event name",
Category: "Please choose a category"
},
submitHandler: function(form) {
alert("validated");
// $('#loading_1').show();
// $('#proceed_c').hide();
// $(form).ajaxSubmit();
// //form.submit();
},
errorPlacement: function(error, element) {
error.appendTo(element.next(".status"));
}
});
}
là vấn đề với beforeSend
trong submitFormWithAjax function
, vị trí của $("#event_form").validate
hoặc submitHandler: function(form)
bên trong nó? Chúng tôi rất trân trọng bất kỳ sự giúp đỡ nào.
Bạn có thể cho rằng lớp '.error' đang được thêm vào các yếu tố của bạn khi họ đang không hợp lệ? –