22 parent::__construct( $params );
25 if ( !isset( $this->mParams[
'disabled-options'] ) ) {
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 ) ) {
54 $value = array_filter( $value,
'is_scalar' );
56 # If all options are valid, array_intersect of the valid options
57 # and the provided options will return the provided options.
60 $validValues = array_intersect( $value, $validOptions );
61 if ( count( $validValues ) == count( $value ) ) {
64 return $this->
msg(
'htmlform-select-badoption' );
73 if ( isset( $this->mParams[
'dropdown'] ) ) {
74 $this->mParent->getOutput()->addModules(
'jquery.chosen' );
95 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
97 foreach ( $options as $label => $info ) {
98 if ( is_array( $info ) ) {
99 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
103 'id' =>
"{$this->mID}-$info",
106 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
107 $thisAttribs[
'disabled'] =
'disabled';
109 $checked = in_array( $info, $value,
true );
111 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
113 $html .=
' ' . Html::rawElement(
115 [
'class' =>
'mw-htmlform-flatlist-item' ],
126 throw new MWException(
'HTMLMultiSelectField#getOneCheckbox() is not supported' );
128 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
130 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
132 call_user_func( $elementFunc,
134 [
'for' => $attribs[
'id'] ],
137 if ( $this->mParent->getConfig()->get(
'UseMediaWikiUIEverywhere' ) ) {
138 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
140 Html::closeElement(
'div' );
154 throw new MWException(
'HTMLMultiSelectField#getOptionsOOUI() is not supported' );
170 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
173 $value = array_filter( $value,
'is_scalar' );
175 $hasSections =
false;
176 $optionsOouiSections = [];
180 foreach ( $options as $label => $section ) {
181 if ( is_array( $section ) ) {
182 $optionsOouiSections[ $label ] = Xml::listDropDownOptionsOoui( $section );
183 unset( $options[$label] );
190 $optionsOouiSections = array_merge(
191 [
'' => Xml::listDropDownOptionsOoui( $options ) ],
195 '@phan-var array[][] $optionsOouiSections';
198 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
200 $attr[
'name'] =
"{$this->mName}[]";
202 $attr[
'value'] = $value;
204 $options = $optionsOoui;
205 foreach ( $options as &$option ) {
206 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
208 if ( $this->mOptionsLabelsNotFromMessage ) {
209 foreach ( $options as &$option ) {
211 $option[
'label'] =
new OOUI\HtmlSnippet( $option[
'label'] );
215 $attr[
'options'] = $options;
217 $attr += OOUI\Element::configFromHtmlAttributes(
221 if ( $this->mClass !==
'' ) {
222 $attr[
'classes'] = [ $this->mClass ];
225 $widget =
new OOUI\CheckboxMultiselectInputWidget( $attr );
226 if ( $sectionLabel ) {
227 $out[] =
new OOUI\FieldsetLayout( [
228 'items' => [ $widget ],
230 'label' =>
new OOUI\HtmlSnippet( $sectionLabel ),
237 if ( !$hasSections && $out ) {
243 return implode(
'', $out );
253 $fromRequest = $request->getArray( $this->mName, [] );
272 return $this->mDefault ?? [];
284 foreach ( $options as $opt ) {
285 $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...
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)
getDefault()
to override mixed
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
loadDataFromRequest( $request)