22 parent::__construct( $params );
25 if ( isset( $this->mParams[
'disabled-options'] ) ===
false ) {
26 $this->mParams[
'disabled-options'] = [];
29 if ( isset( $params[
'dropdown'] ) ) {
30 $this->mClass .=
' mw-htmlform-dropdown';
33 if ( isset( $params[
'flatlist'] ) ) {
34 $this->mClass .=
' mw-htmlform-flatlist';
43 $p = parent::validate( $value, $alldata );
49 if ( !is_array( $value ) ) {
53 # If all options are valid, array_intersect of the valid options
54 # and the provided options will return the provided options.
57 $validValues = array_intersect( $value, $validOptions );
58 if ( count( $validValues ) == count( $value ) ) {
61 return $this->
msg(
'htmlform-select-badoption' );
70 if ( isset( $this->mParams[
'dropdown'] ) ) {
71 $this->mParent->getOutput()->addModules(
'jquery.chosen' );
92 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
94 foreach ( $options as $label => $info ) {
95 if ( is_array( $info ) ) {
96 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
100 'id' =>
"{$this->mID}-$info",
103 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
104 $thisAttribs[
'disabled'] =
'disabled';
106 $checked = in_array( $info, $value,
true );
108 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
110 $html .=
' ' . Html::rawElement(
112 [
'class' =>
'mw-htmlform-flatlist-item' ],
123 throw new MWException(
'HTMLMultiSelectField#getOneCheckbox() is not supported' );
125 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
127 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
129 call_user_func( $elementFunc,
131 [
'for' => $attribs[
'id'] ],
134 if ( $this->mParent->getConfig()->get(
'UseMediaWikiUIEverywhere' ) ) {
135 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
137 Html::closeElement(
'div' );
150 throw new MWException(
'HTMLMultiSelectField#getOptionsOOUI() is not supported' );
166 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
168 $hasSections =
false;
169 $optionsOouiSections = [];
173 foreach ( $options as $label => $section ) {
174 if ( is_array( $section ) ) {
175 $optionsOouiSections[ $label ] = Xml::listDropDownOptionsOoui( $section );
176 unset( $options[$label] );
183 $optionsOouiSections = array_merge(
184 [
'' => Xml::listDropDownOptionsOoui( $options ) ],
188 '@phan-var array[][] $optionsOouiSections';
191 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
193 $attr[
'name'] =
"{$this->mName}[]";
195 $attr[
'value'] = $value;
197 $options = $optionsOoui;
198 foreach ( $options as &$option ) {
199 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
201 if ( $this->mOptionsLabelsNotFromMessage ) {
202 foreach ( $options as &$option ) {
203 $option[
'label'] =
new OOUI\HtmlSnippet( $option[
'label'] );
207 $attr[
'options'] = $options;
209 $attr += OOUI\Element::configFromHtmlAttributes(
213 if ( $this->mClass !==
'' ) {
214 $attr[
'classes'] = [ $this->mClass ];
217 $widget =
new OOUI\CheckboxMultiselectInputWidget( $attr );
218 if ( $sectionLabel ) {
219 $out[] =
new OOUI\FieldsetLayout( [
220 'items' => [ $widget ],
221 'label' =>
new OOUI\HtmlSnippet( $sectionLabel ),
228 if ( !$hasSections && $out ) {
234 return implode(
'', $out );
244 $fromRequest = $request->getArray( $this->mName, [] );
263 return $this->mDefault ?? [];
275 foreach ( $options as $opt ) {
276 $res[
"$opt"] = in_array( $opt, $data,
true );
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
__construct( $params)
Stable to call.
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)
Stable to override.
getDefault()
Stable to override.mixed Stable to override
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
loadDataFromRequest( $request)
Stable to override.