A simple jQuery plugin that helps you bind events to a textbox when hitting Enter (e.g. saving) or hitting ESC (e.g. canceling).
The functionality it provides is very simple and its purpose is to avoid writing over and over again the same trivial code.
This plugin was initially implemented for Aptter, an internal collaboration platform for businesses.
- When saving the onSave callback is called and the new value becomes the original.
- When canceling the onCancel callback is called and the value returns to the original value of the textbox.
In both cases, the events trigger when the textbox has had its original value changed.
jQuery('.some-textbox').smartType({
onSave: function (prev, current, textbox) { console.log('saving'); },
onCancel: function (prev, current, textbox) { console.log('canceling'); }
});
Clear textbox's value when canceling. Default value is false.
Trigger the onSave event if the textbox is empty. Default value is false.
Prevent or not the keyup event to be propagated when saving. Default value is true.
Specify the name of the data- attribute it will be used. Default value is val.
The callback function that is called when the user hits Enter. It has three attributes, the previous value, the current value and the textbox.
The callback function that is called when the user hits ESC. It has three attributes, the previous value, the current value and the textbox.
Renamed to smartType from typeSave.
Changed attributes for the callback functions. Cancel event occurs only when the textbox's value has changed.
Initial commit. Save and Cancel events supported.