Huji has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/328601 )
Change subject: OOjs UI should allow `disabled` to contain an array ...................................................................... OOjs UI should allow `disabled` to contain an array Bug: T153927 Change-Id: I32fa20e4adb23960d9db6bf6023f79bf128fb600 --- M php/Element.php M php/Widget.php M php/widgets/CheckboxMultiselectInputWidget.php 3 files changed, 30 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/01/328601/1 diff --git a/php/Element.php b/php/Element.php index 9441c7f..962b650 100644 --- a/php/Element.php +++ b/php/Element.php @@ -267,13 +267,13 @@ */ public static function configFromHtmlAttributes( array $attrs ) { $booleanAttrs = [ - 'disabled' => true, 'required' => true, 'autofocus' => true, 'multiple' => true, 'readonly' => true, ]; $attributeToConfig = [ + 'disabled' => 'disabled', 'maxlength' => 'maxLength', 'readonly' => 'readOnly', 'tabindex' => 'tabIndex', diff --git a/php/Widget.php b/php/Widget.php index b5ec488..b41bbf5 100644 --- a/php/Widget.php +++ b/php/Widget.php @@ -64,10 +64,14 @@ * @return $this */ public function setDisabled( $disabled ) { - $this->disabled = !!$disabled; - $this->toggleClasses( [ 'oo-ui-widget-disabled' ], $this->disabled ); - $this->toggleClasses( [ 'oo-ui-widget-enabled' ], !$this->disabled ); - $this->setAttributes( [ 'aria-disabled' => $this->disabled ? 'true' : 'false' ] ); + if( gettype($disabled) == 'array' ) { + $this->disabled = $disabled; + } else { + $this->disabled = !!$disabled; + $this->toggleClasses( [ 'oo-ui-widget-disabled' ], $this->disabled ); + $this->toggleClasses( [ 'oo-ui-widget-enabled' ], !$this->disabled ); + $this->setAttributes( [ 'aria-disabled' => $this->disabled ? 'true' : 'false' ] ); + } return $this; } diff --git a/php/widgets/CheckboxMultiselectInputWidget.php b/php/widgets/CheckboxMultiselectInputWidget.php index a9b8da4..a221556 100644 --- a/php/widgets/CheckboxMultiselectInputWidget.php +++ b/php/widgets/CheckboxMultiselectInputWidget.php @@ -99,6 +99,26 @@ } /** + * Get the value for the `disabled` parameter + * + * If `disabled` is an array, check if the current option + * is in that array, if so return true, else return false. + * + * If `disabled` is not an array, then you would expect it to be boolean + * so simply pass its value. + * + * @param OOUI\CheckboxMultiselectInputWidget $widget The checkboxmultiselect object + * @param string $option The value of the current object + */ + protected function getDisabled( $widget, $option ){ + if( gettype( $widget->isDisabled() ) == 'array' ) { + return in_array( $option, $widget->isDisabled() ); + } else { + return $widget->isDisabled(); + } + } + + /** * Set the options available for this input. * * @param array[] $options Array of menu options in the format @@ -117,7 +137,7 @@ new CheckboxInputWidget( [ 'name' => $name, 'value' => $optValue, - 'disabled' => $this->isDisabled(), + 'disabled' => $this->getDisabled( $this, $optValue ), ] ), [ 'label' => isset( $opt['label'] ) ? $opt['label'] : $optValue, -- To view, visit https://gerrit.wikimedia.org/r/328601 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I32fa20e4adb23960d9db6bf6023f79bf128fb600 Gerrit-PatchSet: 1 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Huji <huji.h...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits