Form Reset Mixin
Description: A mixin to call refresh()
on an input widget when the parent form gets reset.
This only works for native input elements that have a form attribute, like an
<input>
. It doesn't work for other elements like <label>
or <div>
Methods
_bindFormResetHandler()Returns: jQuery (plugin only)
Call
this._bindFormResetHandler()
inside _create()
to initialize the mixin. - This method does not accept any arguments.
Code examples:
Set the background color of the widget's element based on an option.
_create: function() { this._bindFormResetHandler(); }
_unbindFormResetHandler()Returns: jQuery (plugin only)
Call
this._unbindFormResetHandler()
inside _destroy()
to destroy the mixin. - This method does not accept any arguments.
Code examples:
_destroy: function() { this._unbindFormResetHandler(); }
Example:
Type colors into the input
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery.ui.formResetMixin demo</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css"> <style> .demo-colorize-swatch { width: 50px; height: 50px; border: 1px solid black; } </style> <script src="//code.jquery.com/jquery-1.12.4.js"></script> <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <form> <input id="colorize"> <button type="reset">Reset form</button> </form> <script> $.widget( "custom.colorize", [ $.ui.formResetMixin, { _create: function() { this.swatch = $("<div>") .addClass("demo-colorize-swatch") .insertAfter(this.element); this.refresh(); this._bindFormResetHandler(); this._on({ keyup: "refresh" }); }, refresh: function() { this.swatch.css( "background-color", this.element.val() ); }, _destroy: function() { this.swatch.remove(); this._unbindFormResetHandler(); } } ] ); $( "#colorize" ).colorize(); </script> </body> </html>