<?php
+
/**
* Multi-select field
*/
class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable {
-
function validate( $value, $alldata ) {
$p = parent::validate( $value, $alldata );
return $p;
}
- if ( ! is_array( $value ) ) {
+ if ( !is_array( $value ) ) {
return false;
}
# If all options are valid, array_intersect of the valid options
# and the provided options will return the provided options.
- $validOptions = HTMLFormField::flattenOptions( $this->mParams[ 'options' ] );
+ $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
$validValues = array_intersect( $value, $validOptions );
if ( count( $validValues ) == count( $value ) ) {
}
function getInputHTML( $value ) {
- $html = $this->formatOptions( $this->mParams[ 'options' ], $value );
+ $html = $this->formatOptions( $this->mParams['options'], $value );
return $html;
}
function formatOptions( $options, $value ) {
$html = '';
- $attribs = array();
-
- if ( ! empty( $this->mParams[ 'disabled' ] ) ) {
- $attribs[ 'disabled' ] = 'disabled';
- }
+ $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
foreach ( $options as $label => $info ) {
if ( is_array( $info ) ) {
} else {
$thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
- $checkbox = Xml::check( $this->mName . '[]', in_array( $info, $value, true ), $attribs + $thisAttribs );
- $checkbox .= ' ' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
-
- $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $checkbox );
+ $checkbox = Xml::check(
+ $this->mName . '[]',
+ in_array( $info, $value, true ),
+ $attribs + $thisAttribs
+ );
+ $checkbox .= ' ' . Html::rawElement(
+ 'label',
+ array( 'for' => "{$this->mID}-$info" ),
+ $label
+ );
+
+ $html .= ' ' . Html::rawElement(
+ 'div',
+ array( 'class' => 'mw-htmlform-flatlist-item' ),
+ $checkbox
+ );
}
}
}
function filterDataForSubmit( $data ) {
- $options = HTMLFormField::flattenOptions( $this->mParams[ 'options' ] );
+ $options = HTMLFormField::flattenOptions( $this->mParams['options'] );
$res = array();
foreach ( $options as $opt ) {
- $res[ "$opt" ] = in_array( $opt, $data );
+ $res["$opt"] = in_array( $opt, $data );
}
return $res;
protected function needsLabel() {
return false;
}
-}
\ No newline at end of file
+}