jenkins-bot has submitted this change and it was merged.

Change subject: DropdownInputWidget, RadioSelectInputWidget: Consistently call 
#cleanUpValue
......................................................................


DropdownInputWidget, RadioSelectInputWidget: Consistently call #cleanUpValue

By default, the primary purpose of #cleanUpValue is to cast everything
to strings.

On PHP side, we were calling #cleanUpValue when setting a value, but
not when building the list of possible values. This meant that, for
example, if all values were consistently passed in as integers, the
given 'value' would essentially be ignored.

On JS side, we weren't calling #cleanUpValue at all anywhere. This
meant that #getValue would return whatever was passed in to widget
config and not strings, contrary to documentation.

Reported by Florian when working on I47a86492.

Change-Id: I2d35669dadc355b443472c12b9e489a5accf4b43
---
M php/widgets/DropdownInputWidget.php
M php/widgets/RadioSelectInputWidget.php
M src/widgets/DropdownInputWidget.js
M src/widgets/RadioSelectInputWidget.js
4 files changed, 22 insertions(+), 12 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  Florianschmidtwelzow: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/php/widgets/DropdownInputWidget.php 
b/php/widgets/DropdownInputWidget.php
index ae541a6..1e099a2 100644
--- a/php/widgets/DropdownInputWidget.php
+++ b/php/widgets/DropdownInputWidget.php
@@ -60,11 +60,12 @@
                // Rebuild the dropdown menu
                $this->input->clearContent();
                foreach ( $options as $opt ) {
+                       $optValue = $this->cleanUpValue( $opt['data'] );
                        $option = new Tag( 'option' );
-                       $option->setAttributes( array( 'value' => $opt['data'] 
) );
-                       $option->appendContent( isset( $opt['label'] ) ? 
$opt['label'] : $opt['data'] );
+                       $option->setAttributes( array( 'value' => $optValue ) );
+                       $option->appendContent( isset( $opt['label'] ) ? 
$opt['label'] : $optValue );
 
-                       if ( $value === $opt['data'] ) {
+                       if ( $value === $optValue ) {
                                $isValueAvailable = true;
                        }
 
diff --git a/php/widgets/RadioSelectInputWidget.php 
b/php/widgets/RadioSelectInputWidget.php
index 7d9f2c8..923578d 100644
--- a/php/widgets/RadioSelectInputWidget.php
+++ b/php/widgets/RadioSelectInputWidget.php
@@ -71,19 +71,20 @@
                // Need a unique name, otherwise more than one radio will be 
selectable
                $name = $this->name ?: 'oo-ui-radioSelectInputWidget' . 
mt_rand();
                foreach ( $options as $opt ) {
+                       $optValue = $this->cleanUpValue( $opt['data'] );
                        $field = new FieldLayout(
                                new RadioInputWidget( array(
                                        'name' => $name,
-                                       'value' => $opt['data'],
+                                       'value' => $optValue,
                                        'disabled' => $this->isDisabled(),
                                ) ),
                                array(
-                                       'label' => isset( $opt['label'] ) ? 
$opt['label'] : $opt['data'],
+                                       'label' => isset( $opt['label'] ) ? 
$opt['label'] : $optValue,
                                        'align' => 'inline',
                                )
                        );
 
-                       if ( $value === $opt['data'] ) {
+                       if ( $value === $optValue ) {
                                $isValueAvailable = true;
                        }
 
diff --git a/src/widgets/DropdownInputWidget.js 
b/src/widgets/DropdownInputWidget.js
index fc6ab4b..bf08b3b 100644
--- a/src/widgets/DropdownInputWidget.js
+++ b/src/widgets/DropdownInputWidget.js
@@ -78,6 +78,7 @@
  * @inheritdoc
  */
 OO.ui.DropdownInputWidget.prototype.setValue = function ( value ) {
+       value = this.cleanUpValue( value );
        this.dropdownWidget.getMenu().selectItemByData( value );
        OO.ui.DropdownInputWidget.parent.prototype.setValue.call( this, value );
        return this;
@@ -99,15 +100,18 @@
  * @chainable
  */
 OO.ui.DropdownInputWidget.prototype.setOptions = function ( options ) {
-       var value = this.getValue();
+       var
+               value = this.getValue(),
+               widget = this;
 
        // Rebuild the dropdown menu
        this.dropdownWidget.getMenu()
                .clearItems()
                .addItems( options.map( function ( opt ) {
+                       var optValue = widget.cleanUpValue( opt.data );
                        return new OO.ui.MenuOptionWidget( {
-                               data: opt.data,
-                               label: opt.label !== undefined ? opt.label : 
opt.data
+                               data: optValue,
+                               label: opt.label !== undefined ? opt.label : 
optValue
                        } );
                } ) );
 
diff --git a/src/widgets/RadioSelectInputWidget.js 
b/src/widgets/RadioSelectInputWidget.js
index f0c3adb..64258e0 100644
--- a/src/widgets/RadioSelectInputWidget.js
+++ b/src/widgets/RadioSelectInputWidget.js
@@ -78,6 +78,7 @@
  * @inheritdoc
  */
 OO.ui.RadioSelectInputWidget.prototype.setValue = function ( value ) {
+       value = this.cleanUpValue( value );
        this.radioSelectWidget.selectItemByData( value );
        OO.ui.RadioSelectInputWidget.parent.prototype.setValue.call( this, 
value );
        return this;
@@ -99,15 +100,18 @@
  * @chainable
  */
 OO.ui.RadioSelectInputWidget.prototype.setOptions = function ( options ) {
-       var value = this.getValue();
+       var
+               value = this.getValue(),
+               widget = this;
 
        // Rebuild the radioSelect menu
        this.radioSelectWidget
                .clearItems()
                .addItems( options.map( function ( opt ) {
+                       var optValue = widget.cleanUpValue( opt.data );
                        return new OO.ui.RadioOptionWidget( {
-                               data: opt.data,
-                               label: opt.label !== undefined ? opt.label : 
opt.data
+                               data: optValue,
+                               label: opt.label !== undefined ? opt.label : 
optValue
                        } );
                } ) );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/223076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2d35669dadc355b443472c12b9e489a5accf4b43
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz DziewoƄski <matma....@gmail.com>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to