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

Change subject: [BREAKING CHANGE] CheckboxInputWidget: Allow setting HTML 
'value' attribute
......................................................................


[BREAKING CHANGE] CheckboxInputWidget: Allow setting HTML 'value' attribute

Previously we were using the #setValue/#getValue methods (and 'value'
config parameter) to set checkedness state of the input, rather than
its HTML 'value' attribute. This was just fine in JS, but we need to
be able to set the value in server-side usage in PHP.

Like RadioInputWidget, CheckboxInputWidget now has two new methods:
#setSelected and #isSelected. These need to be used where #setValue
and #getValue were used previously.

Bug: T76645
Change-Id: I32608c7f3f3c20ab5c0c6308d62458175a171b3b
---
M demos/pages/widgets.js
M demos/widgets.php
M php/widgets/CheckboxInputWidget.php
M src/widgets/CheckboxInputWidget.js
4 files changed, 50 insertions(+), 44 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  Trevor Parscal: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/demos/pages/widgets.js b/demos/pages/widgets.js
index 840ca35..ee79b76 100644
--- a/demos/pages/widgets.js
+++ b/demos/pages/widgets.js
@@ -595,7 +595,7 @@
                ),
                new OO.ui.FieldLayout(
                        new OO.ui.CheckboxInputWidget( {
-                               value: true
+                               selected: true
                        } ),
                        {
                                align: 'inline',
@@ -604,7 +604,7 @@
                ),
                new OO.ui.FieldLayout(
                        new OO.ui.CheckboxInputWidget( {
-                               value: true,
+                               selected: true,
                                disabled: true
                        } ),
                        {
diff --git a/demos/widgets.php b/demos/widgets.php
index 52df927..90676a4 100644
--- a/demos/widgets.php
+++ b/demos/widgets.php
@@ -228,7 +228,7 @@
                                                        new OOUI\FieldLayout(
                                                                new 
OOUI\CheckboxInputWidget( array(
                                                                        'name' 
=> 'rememberme',
-                                                                       'value' 
=> true,
+                                                                       
'selected' => true,
                                                                ) ),
                                                                array(
                                                                        'label' 
=> 'Remember me',
@@ -335,7 +335,7 @@
                                                ),
                                                new OOUI\FieldLayout(
                                                        new 
OOUI\CheckboxInputWidget( array(
-                                                               'value' => true
+                                                               'selected' => 
true
                                                        ) ),
                                                        array(
                                                                'align' => 
'inline',
@@ -344,7 +344,7 @@
                                                ),
                                                new OOUI\FieldLayout(
                                                        new 
OOUI\CheckboxInputWidget( array(
-                                                               'value' => true,
+                                                               'selected' => 
true,
                                                                'disabled' => 
true
                                                        ) ),
                                                        array(
diff --git a/php/widgets/CheckboxInputWidget.php 
b/php/widgets/CheckboxInputWidget.php
index 17b16f4..3bb54bb 100644
--- a/php/widgets/CheckboxInputWidget.php
+++ b/php/widgets/CheckboxInputWidget.php
@@ -9,6 +9,8 @@
 
        /**
         * @param array $config Configuration options
+        * @param boolean $config['selected'] Whether the checkbox is initially 
selected
+        *   (default: false)
         */
        public function __construct( array $config = array() ) {
                // Parent constructor
@@ -16,6 +18,7 @@
 
                // Initialization
                $this->addClasses( array( 'oo-ui-checkboxInputWidget' ) );
+               $this->setSelected( isset( $config['selected'] ) ? 
$config['selected'] : false );
        }
 
        protected function getInputElement( $config ) {
@@ -25,27 +28,26 @@
        }
 
        /**
-        * Get checked state of the checkbox
+        * Set selection state of this checkbox.
         *
-        * @return boolean If the checkbox is checked
+        * @param boolean $state Whether the checkbox is selected
         */
-       public function getValue() {
-               return $this->value;
-       }
-
-       /**
-        * Set checked state of the checkbox
-        *
-        * @param boolean $value New value
-        * @chainable
-        */
-       public function setValue( $value ) {
-               $this->value = (bool)$value;
-               if ( $this->value ) {
+       public function setSelected( $state ) {
+               $this->selected = (bool)$state;
+               if ( $this->selected ) {
                        $this->input->setAttributes( array( 'checked' => 
'checked' ) );
                } else {
                        $this->input->removeAttributes( array( 'checked' ) );
                }
                return $this;
        }
+
+       /**
+        * Check if this checkbox is selected.
+        *
+        * @return boolean Checkbox is selected
+        */
+       public function isSelected() {
+               return $this->selected;
+       }
 }
diff --git a/src/widgets/CheckboxInputWidget.js 
b/src/widgets/CheckboxInputWidget.js
index 537edf5..c0dc706 100644
--- a/src/widgets/CheckboxInputWidget.js
+++ b/src/widgets/CheckboxInputWidget.js
@@ -6,6 +6,7 @@
  *
  * @constructor
  * @param {Object} [config] Configuration options
+ * @cfg {boolean} [selected=false] Whether the checkbox is initially selected
  */
 OO.ui.CheckboxInputWidget = function OoUiCheckboxInputWidget( config ) {
        // Parent constructor
@@ -13,6 +14,7 @@
 
        // Initialization
        this.$element.addClass( 'oo-ui-checkboxInputWidget' );
+       this.setSelected( config.selected !== undefined ? config.selected : 
false );
 };
 
 /* Setup */
@@ -32,29 +34,6 @@
 };
 
 /**
- * Get checked state of the checkbox
- *
- * @return {boolean} If the checkbox is checked
- */
-OO.ui.CheckboxInputWidget.prototype.getValue = function () {
-       return this.value;
-};
-
-/**
- * Set checked state of the checkbox
- *
- * @param {boolean} value New value
- */
-OO.ui.CheckboxInputWidget.prototype.setValue = function ( value ) {
-       value = !!value;
-       if ( this.value !== value ) {
-               this.value = value;
-               this.$input.prop( 'checked', this.value );
-               this.emit( 'change', this.value );
-       }
-};
-
-/**
  * @inheritdoc
  */
 OO.ui.CheckboxInputWidget.prototype.onEdit = function () {
@@ -62,7 +41,32 @@
        if ( !this.isDisabled() ) {
                // Allow the stack to clear so the value will be updated
                setTimeout( function () {
-                       widget.setValue( widget.$input.prop( 'checked' ) );
+                       widget.setSelected( widget.$input.prop( 'checked' ) );
                } );
        }
 };
+
+/**
+ * Set selection state of this checkbox.
+ *
+ * @param {boolean} state Whether the checkbox is selected
+ * @chainable
+ */
+OO.ui.CheckboxInputWidget.prototype.setSelected = function ( state ) {
+       state = !!state;
+       if ( this.selected !== state ) {
+               this.selected = state;
+               this.$input.prop( 'checked', this.selected );
+               this.emit( 'change', this.selected );
+       }
+       return this;
+};
+
+/**
+ * Check if this checkbox is selected.
+ *
+ * @return {boolean} Checkbox is selected
+ */
+OO.ui.CheckboxInputWidget.prototype.isSelected = function () {
+       return this.selected;
+};

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I32608c7f3f3c20ab5c0c6308d62458175a171b3b
Gerrit-PatchSet: 3
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to