Reputation: 549
When I add the card to the in box. Then it is possible to double click on the card, and dialog pop up. In the dialog I have Tow buttons (Save) and (Cancel). When I press Cancel buttons a confirm window pop-ups.
I want when I press the Save button, and after there press the Cancel Button this confirm window should not pop-up. But if I didn't save the data, and press the cancel button the confirm window should pop-up. I tried by my self to fix it with boolean and if sentence, but don't succeed.
I have a Demo
// Double click to open Modal Dialog Window
$('#userAddedCard').dblclick(function (e) {
$currentTarget = $(e.target);
$('#modalDialog').dialog({
modal: true,
height: 600,
width: 500,
position: 'center',
buttons: {
Save: function () { //submit
save(true);
},
Cancel: function () { //cancel
cancel(true);
}
}
});
});
function save() {
var val = $("#customTextBox").val();
$currentTarget.find(".ctb").val(val);
$currentTarget.find(".date").val($("#datepicker").val());
}
function cancel() {
$('#dialog-confirm').dialog({
resizable: false,
height: 300,
modal: true,
draggable: false,
buttons: {
YES: function () {
$(this).dialog("close");
$('#modalDialog').dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
Upvotes: 0
Views: 378
Reputation: 447
use boolean
// Double click to open Modal Dialog Window
$('#userAddedCard').dblclick(function (e) {
$currentTarget = $(e.target);
$('#modalDialog').dialog({
modal: true,
height: 600,
width: 500,
position: 'center',
buttons: {
Save: function () { //submit
save(true);
},
Cancel: function () { //cancel
cancel(true);
}
}
});
});
var boolean = false;
function save() {
var val = $("#customTextBox").val();
$currentTarget.find(".ctb").val(val);
$currentTarget.find(".date").val($("#datepicker").val());
boolean = true;
}
function cancel() {
if(!boolean){
$('#dialog-confirm').dialog({
resizable: false,
height: 300,
modal: true,
draggable: false,
buttons: {
YES: function () {
$(this).dialog("close");
$('#modalDialog').dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
else{
$('#dialog-confirm').hide();
}
}
when you click on cancel it display pup-up and when you click it on after save click on save button its hide.
Upvotes: 1