2 * jQuery UI Form Reset Mixin 1.12.1
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
10 //>>label: Form Reset Mixin
12 //>>description: Refresh input widgets when their form is reset
13 //>>docs: http://api.jqueryui.com/form-reset-mixin/
15 ( function( factory ) {
16 if ( typeof define === "function" && define.amd ) {
18 // AMD. Register as an anonymous module.
31 return $.ui.formResetMixin = {
32 _formResetHandler: function() {
35 // Wait for the form reset to actually happen before refreshing
36 setTimeout( function() {
37 var instances = form.data( "ui-form-reset-instances" );
38 $.each( instances, function() {
44 _bindFormResetHandler: function() {
45 this.form = this.element.form();
46 if ( !this.form.length ) {
50 var instances = this.form.data( "ui-form-reset-instances" ) || [];
51 if ( !instances.length ) {
53 // We don't use _on() here because we use a single event handler per form
54 this.form.on( "reset.ui-form-reset", this._formResetHandler );
56 instances.push( this );
57 this.form.data( "ui-form-reset-instances", instances );
60 _unbindFormResetHandler: function() {
61 if ( !this.form.length ) {
65 var instances = this.form.data( "ui-form-reset-instances" );
66 instances.splice( $.inArray( this, instances ), 1 );
67 if ( instances.length ) {
68 this.form.data( "ui-form-reset-instances", instances );
71 .removeData( "ui-form-reset-instances" )
72 .off( "reset.ui-form-reset" );