function ValidateField(){
var bAllow= true;
//some checking here
if (bAllow == true && apl.val().trim() == \"\")
{
showDialog();
showDialog()
why not use the reject method instaed of resolve("false"). You will then be able to pass an object as argument. Let's say you have multiple fieldsets of inputs, each one having a delete button :
function confirmation(question,obj) {
var defer = $.Deferred();
$('')
.html(question)
.dialog({
autoOpen: true,
modal: true,
title: 'Confirmation',
buttons: {
"Oui": function () {
defer.resolve(obj);// pass the object to delete to the defer object
$(this).dialog("close");
},
"Non": function () {
defer.reject();//reject, no need to pass the object
$(this).dialog("close");
}
},
close: function () {
$(this).dialog('destroy').remove()
}
});
return defer.promise();
}
$(document).on("click", ".btn-suppr",function (){// all delete buttons having a class btn-suppr
var question = "Are you sure to delete this fieldset ?";
confirmation(question,$(this)).then(function (obj) {
obj.parent('fieldset').remove(); // remove the parent fieldset of the delete button if confirmed
});
});