Add support for form reset functionality.#154
Add support for form reset functionality.#154Haprog wants to merge 3 commits intosliptree:masterfrom
Conversation
Tokens are now automatically updated after form reset to reflect the new input value after reset.
|
I also made an enhancement to this that triggers a new custom event This is the enhanced implementation: // Update tokens on form reset
this.$element.closest('form').on('reset', function (e) {
var form = this;
var oldValue = _self.$element.val();
// Set a timeout to run code after the reset event is finished
window.setTimeout(function(){
var newValue = _self.$element.val();
// If the value changed due to form reset then update tokens
if (oldValue != newValue) {
_self.setTokens(newValue, false, false);
}
var eventOptions = {
attrs: {
oldValue: oldValue,
newValue: newValue
},
relatedTarget: form
};
var postResetEvent = $.Event('tokenfield:postreset', eventOptions);
_self.$element.trigger(postResetEvent);
}, 0);
});But I didn't publish this yet so if this is ok, I can either push it to my branch for this pull request or make a new pull request after this has been merged unless you want some changes to this. |
|
I just realized that this event listener should probably be moved to I can make the changes if you confirm that this is how it should be done. |
|
@Haprog Good catch. This should definitely be in the |
Fix issue #111
Tokens are now automatically updated after form reset to reflect the new input value after reset.