18 parent::__construct( $params );
21 if ( isset( $this->mParams[
'disabled-options'] ) ===
false ) {
22 $this->mParams[
'disabled-options'] = [];
25 if ( isset( $params[
'dropdown'] ) ) {
26 $this->mClass .=
' mw-htmlform-dropdown';
29 if ( isset( $params[
'flatlist'] ) ) {
30 $this->mClass .=
' mw-htmlform-flatlist';
35 $p = parent::validate( $value, $alldata );
41 if ( !is_array( $value ) ) {
45 # If all options are valid, array_intersect of the valid options
46 # and the provided options will return the provided options.
49 $validValues = array_intersect( $value, $validOptions );
50 if ( count( $validValues ) == count( $value ) ) {
53 return $this->
msg(
'htmlform-select-badoption' );
58 if ( isset( $this->mParams[
'dropdown'] ) ) {
59 $this->mParent->getOutput()->addModules(
'jquery.chosen' );
71 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
73 foreach ( $options as $label => $info ) {
74 if ( is_array( $info ) ) {
75 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
79 'id' =>
"{$this->mID}-$info",
82 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
83 $thisAttribs[
'disabled'] =
'disabled';
85 $checked = in_array( $info, $value,
true );
87 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
89 $html .=
' ' . Html::rawElement(
91 [
'class' =>
'mw-htmlform-flatlist-item' ],
102 throw new MWException(
'HTMLMultiSelectField#getOneCheckbox() is not supported' );
104 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
106 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
108 call_user_func( $elementFunc,
110 [
'for' => $attribs[
'id'] ],
113 if ( $this->mParent->getConfig()->get(
'UseMediaWikiUIEverywhere' ) ) {
114 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
116 Html::closeElement(
'div' );
128 throw new MWException(
'HTMLMultiSelectField#getOptionsOOUI() is not supported' );
143 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
145 $hasSections =
false;
146 $optionsOouiSections = [];
150 foreach ( $options as $label => $section ) {
151 if ( is_array( $section ) ) {
152 $optionsOouiSections[ $label ] = Xml::listDropDownOptionsOoui( $section );
153 unset( $options[$label] );
160 $optionsOouiSections = array_merge(
161 [
'' => Xml::listDropDownOptionsOoui( $options ) ],
167 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
169 $attr[
'name'] =
"{$this->mName}[]";
171 $attr[
'value'] = $value;
172 $attr[
'options'] = $optionsOoui;
174 foreach ( $attr[
'options'] as &$option ) {
175 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
177 if ( $this->mOptionsLabelsNotFromMessage ) {
178 foreach ( $attr[
'options'] as &$option ) {
179 $option[
'label'] =
new OOUI\HtmlSnippet( $option[
'label'] );
183 $attr += OOUI\Element::configFromHtmlAttributes(
187 if ( $this->mClass !==
'' ) {
191 $widget =
new OOUI\CheckboxMultiselectInputWidget( $attr );
192 if ( $sectionLabel ) {
193 $out[] =
new OOUI\FieldsetLayout( [
194 'items' => [ $widget ],
195 'label' =>
new OOUI\HtmlSnippet( $sectionLabel ),
202 if ( !$hasSections ) {
208 return implode(
'', $out );
217 $fromRequest = $request->getArray( $this->mName, [] );
232 return $this->mDefault ?? [];
240 foreach ( $options as $opt ) {
241 $res[
"$opt"] = in_array( $opt, $data,
true );
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
getOneCheckbox( $checked, $attribs, $label)
filterDataForSubmit( $data)
Support for separating multi-option preferences into multiple preferences Due to lack of array suppor...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
getInputOOUI( $value)
Get the OOUI version of this field.
formatOptions( $options, $value)
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
loadDataFromRequest( $request)