Reputation: 61
I'm using a Rails url helper that (for bot protection, etc.) nests redirection inside a form, like so:
<form method="post" action="/projects/1/personal/4/edit_income?criterion=4" class="button-to"><div><input name="_method" type="hidden" value="put" /><input class="requires_confirmation" type="submit" value="edit space parameters" /><input name="authenticity_token" type="hidden" value="4Q/E359jxXUcu7TSVm+cqdjj94RAdQpV+DIv7OUQ+Gg=" /></div></form>
(Above, the method doesn't have to be a POST...)
I want to handle clicks on this .button-to element with jQuery UI Dialog, like so:
$('.button-to').click(function(e){
$( "#dialog-confirm" ).dialog({
resizable: false,
height:250,
buttons: {
"Save": function() {
// SAVE CERTAIN DATA ELEMENTS HERE...
$( this ).dialog( "close" );
// FOLLOW FORM REDIRECT...
},
"Don't save": function() {
$( this ).dialog( "close" );
// FOLLOW FORM REDIRECT...
},
Cancel: function() {
$( this ).dialog( "close" );
// BUT CANCEL REDIRECT IN THIS CASE!
}
}
});
})
It seems like this kind of thing would come up all the time, but I can find nothing helping me toward the result I seek. Any suggestions?
Thanks,
Lille
Upvotes: 0
Views: 729
Reputation: 11
Came across this question after posting a similar one. Basically, I found using the .data
collection works best. Set some vars in $('#dialog').data
before instantiation and then you can use the form to modify them as needed.
Then you can use the public methods of the dialog (or your own) to examine those values and act accordingly.
For more in see my question and my response to myself for the similar question.
Upvotes: 1