annantDev
annantDev

Reputation: 367

Knockout.js - How to revert to previous value in a Dropdown

On my page, when a user changes a dropdown selection, I have to show a prompt "Are you sure you want to continue?". If they click yes, then proceed with the new value else keep the old value in the dropdown.

How can this be done?

Thanks

Upvotes: 1

Views: 2673

Answers (1)

Ryan
Ryan

Reputation: 4313

Here's an example of a "protected observable". You could extend this to display a prompt when a new value is submitted, then call .reset() or .commit().

http://www.knockmeout.net/2011/03/guard-your-model-accept-or-cancel-edits.html

ps. as a user I hate popup prompts. Perhaps having a confirm/reset button that shows up when the drop down changes would be better. Look at Ryan's jsFiddle sample.

Upvotes: 4

Related Questions