Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.UsersMultiselectWidget.js
index d250ad8..e37da8b 100644 (file)
@@ -4,7 +4,7 @@
  * @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
  * @license The MIT License (MIT); see LICENSE.txt
  */
-( function ( $, mw ) {
+( function () {
 
        /**
         * UsersMultiselectWidget can be used to input list of users in a single
                this.limit = config.limit;
 
                if ( 'name' in config ) {
-                       // If used inside HTML form, then create hidden input, which will store
-                       // the results.
-                       this.hiddenInput = $( '<input>' )
-                               .attr( 'type', 'hidden' )
+                       // Use this instead of <input type="hidden">, because hidden inputs do not have separate
+                       // 'value' and 'defaultValue' properties. The script on Special:Preferences
+                       // (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
+                       this.hiddenInput = $( '<textarea>' )
+                               .addClass( 'oo-ui-element-hidden' )
                                .attr( 'name', config.name )
                                .appendTo( this.$element );
-
                        // Update with preset values
                        this.updateHiddenInput();
+                       // Set the default value (it might be different from just being empty)
+                       this.hiddenInput.prop( 'defaultValue', this.getSelectedUsernames().join( '\n' ) );
                }
 
                this.menu = this.getMenu();
        mw.widgets.UsersMultiselectWidget.prototype.updateHiddenInput = function () {
                if ( 'hiddenInput' in this ) {
                        this.hiddenInput.val( this.getSelectedUsernames().join( '\n' ) );
-                       // Hidden inputs do not trigger onChange.
-                       // @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden
+                       // Trigger a 'change' event as if a user edited the text
+                       // (it is not triggered when changing the value from JS code).
                        this.hiddenInput.trigger( 'change' );
                }
        };
                this.input.setValue( '' );
        };
 
-}( jQuery, mediaWiki ) );
+}() );