我正在尝试在对话框中显示警告消息(验证错误消息)。
当打开警告框时,它会自动关闭现有的打开对话框。我想确保在显示错误消息时对话框不会自动关闭。
有人可以帮忙吗?
<div id="dialog-form" title="Create new category">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="code">Code</label>
<input type="text" name="code" maxlength="9" id="code" value="" class="text ui-widget-content ui-corner-all"/>
<label for="name">Year</label>
<input type="text" name="name" id="name" maxlength="4" value=""
class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
$(function () {
var new_dialog = function (type, row) {
var dlg = $("#dialog-form").clone();
var year = dlg.find(("#acad_year")),
code = dlg.find(("#acad_code"));
type = type || 'Create';
var config = {
autoOpen: true,
height: 300,
width: 350,
modal: true,
buttons: {
"Create Academic Year": function () {
save_data("create");
},
"Cancel": function () {
dlg.dialog("close");
}
},
close: function () {
dlg.remove();
}
};
function save_data(strings) {
var id;
dlg.dialog("close");
if (strings == 'edit') {
id = $(row.children().get(0)).text();
} else {
id = "NU=L";
}
$.ajax({
url: 'acad_year.php',
type: 'post',
dataType: 'json',
data: {
id: id,
from: strings,
acad_year: year.val(),
acad_code: code.val()
},
success: function (response) {
if (response[0] === "REDUNDANT") {
alert("Data already exists. ");
}else if(response[0] === "EMPTY"){
alert("Data can't be left empty ");
} else {
sortTable(1);
$("#acodes tbody").append("<tr>" + "<td style='display:none;'>" + response[1] + "<td>" + year.val() + "</td>" + "<td>" + code.val() + "</td>" + "<td><a href='' class='edit'>Edit</a></td>" + "<td><span id='" + response[1] + "' class='delete'><a href=''>Delete</a></span></td>" + "</tr>");
}
},
error: function (error) {
alert("ERROR.." + error[0]);
}
});
}
};