2015-10-26 16:52:42 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Form Reset Mixin @VERSION
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jqueryui.com
|
2015-10-26 16:52:42 +00:00
|
|
|
*
|
2022-07-19 07:36:55 +00:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2015-10-26 16:52:42 +00:00
|
|
|
* Released under the MIT license.
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jquery.org/license
|
2015-10-26 16:52:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//>>label: Form Reset Mixin
|
|
|
|
//>>group: Core
|
|
|
|
//>>description: Refresh input widgets when their form is reset
|
2024-04-26 14:25:34 +00:00
|
|
|
//>>docs: https://api.jqueryui.com/form-reset-mixin/
|
2015-10-26 16:52:42 +00:00
|
|
|
|
2015-04-23 19:11:41 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-04-23 19:11:41 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-07-16 13:14:58 +00:00
|
|
|
"./form",
|
2015-07-15 22:26:12 +00:00
|
|
|
"./version"
|
2015-04-23 19:11:41 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2015-04-23 19:11:41 +00:00
|
|
|
|
|
|
|
return $.ui.formResetMixin = {
|
|
|
|
_formResetHandler: function() {
|
|
|
|
var form = $( this );
|
|
|
|
|
|
|
|
// Wait for the form reset to actually happen before refreshing
|
|
|
|
setTimeout( function() {
|
|
|
|
var instances = form.data( "ui-form-reset-instances" );
|
|
|
|
$.each( instances, function() {
|
|
|
|
this.refresh();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
_bindFormResetHandler: function() {
|
2016-10-11 13:59:32 +00:00
|
|
|
this.form = this.element._form();
|
2015-04-23 19:11:41 +00:00
|
|
|
if ( !this.form.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var instances = this.form.data( "ui-form-reset-instances" ) || [];
|
|
|
|
if ( !instances.length ) {
|
|
|
|
|
|
|
|
// We don't use _on() here because we use a single event handler per form
|
|
|
|
this.form.on( "reset.ui-form-reset", this._formResetHandler );
|
|
|
|
}
|
|
|
|
instances.push( this );
|
|
|
|
this.form.data( "ui-form-reset-instances", instances );
|
|
|
|
},
|
|
|
|
|
|
|
|
_unbindFormResetHandler: function() {
|
|
|
|
if ( !this.form.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var instances = this.form.data( "ui-form-reset-instances" );
|
|
|
|
instances.splice( $.inArray( this, instances ), 1 );
|
|
|
|
if ( instances.length ) {
|
|
|
|
this.form.data( "ui-form-reset-instances", instances );
|
|
|
|
} else {
|
|
|
|
this.form
|
|
|
|
.removeData( "ui-form-reset-instances" )
|
|
|
|
.off( "reset.ui-form-reset" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|