Reputation: 1381
I have a modal with a cancel/close button.
<button type="button" class="close" data-bind="click: close" aria-hidden="true">×</button>
When the user closes the dialog using cancel, I'd like to notify the host page that the user canceled (as opposed to submitted) the form. How can I do this?
Upvotes: 0
Views: 84
Reputation: 3774
When you open a modal in durandal the method returns a promise which is resolved when the dialog is closed.
An example from http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals.html
app.showMessage('This is a message.').then(function(dialogResult){
//do something with the dialog result here
});
When using a custom modal, you create your own dialogResult when you execute dialog.close()
So you would do something like:
submit: function() {
dialog.close( this, "submitted" );
}
close: function() {
dialog.close( this, "closed" );
}
Then in your host page your code would be:
app.showDialog('views/dialogs/confirm').then(function(dialogResult){
if( dialogResult == 'closed' )
// User closed instead of submitting
});
Upvotes: 1