I'm trying to confirm a submit form that is created using ruby on rails, but before submitting I have a condition that open a confirm popup asking if the user really wants to do it. This is working with the default confirm browser box. But now i'm trying to do it with Jquery UI but it's not working. How can I return true or false using jquery ui ?
If the user click "yes" the form should be submitted, if "no" it should just close
this is my jquery ui function:
function confirm(message, callback) {
$('body').append('<div id="confirm" style="display:none">'+message+'</div>');
$( "#confirm" ).dialog({
resizable: false,
title: 'Confirm',
zIndex: 99999999,
modal: true,
buttons: [
{
text: "Yes",
click: function() {
$(this).dialog("close");
if ($.isFunction(callback)) {
callback.apply();
}
}
},{
text: "No",
click: function() { $(this).dialog("close");}
}
],
close: function(event, ui) {
$('#confirm').remove();
}
});
}
And my submit function:
$('form').submit(function(){
<% @meetings.each do |mt| %>
...
<%# cvalue_starthour.value %>
$meeting_dates = [];
...
$.each($meeting_dates, function (index, value) {
$.each($test, function (index2, value2) {
);
if (value.priority == "<%= l(:default_priority_trivial) %>" || "<%= l(:default_priority_minor) %>" || "<%= l(:default_priority_major) %>") {
if ((value.date == value2.date) && (value.time == value2.time)) {
message = confirm("Are you sure?");
}
}
});
});
<% end %>
<% end %>
if (message) {
return true;
} else {
return false;
}
});
});
See Question&Answers more detail:os