f1b058d18ed3225778198f39c73a79ce4698048e
5 class HTMLMultiSelectField
extends HTMLFormField
implements HTMLNestedFilterable
{
7 function validate( $value, $alldata ) {
8 $p = parent
::validate( $value, $alldata );
14 if ( ! is_array( $value ) ) {
18 # If all options are valid, array_intersect of the valid options
19 # and the provided options will return the provided options.
20 $validOptions = HTMLFormField
::flattenOptions( $this->mParams
[ 'options' ] );
22 $validValues = array_intersect( $value, $validOptions );
23 if ( count( $validValues ) == count( $value ) ) {
26 return $this->msg( 'htmlform-select-badoption' )->parse();
30 function getInputHTML( $value ) {
31 $html = $this->formatOptions( $this->mParams
[ 'options' ], $value );
36 function formatOptions( $options, $value ) {
41 if ( ! empty( $this->mParams
[ 'disabled' ] ) ) {
42 $attribs[ 'disabled' ] = 'disabled';
45 foreach ( $options as $label => $info ) {
46 if ( is_array( $info ) ) {
47 $html .= Html
::rawElement( 'h1', array(), $label ) . "\n";
48 $html .= $this->formatOptions( $info, $value );
50 $thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
52 $checkbox = Xml
::check( $this->mName
. '[]', in_array( $info, $value, true ), $attribs +
$thisAttribs );
53 $checkbox .= ' ' . Html
::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
55 $html .= ' ' . Html
::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $checkbox );
63 * @param $request WebRequest
67 function loadDataFromRequest( $request ) {
68 if ( $this->mParent
->getMethod() == 'post' ) {
69 if ( $request->wasPosted() ) {
70 # Checkboxes are just not added to the request arrays if they're not checked,
71 # so it's perfectly possible for there not to be an entry at all
72 return $request->getArray( $this->mName
, array() );
74 # That's ok, the user has not yet submitted the form, so show the defaults
75 return $this->getDefault();
78 # This is the impossible case: if we look at $_GET and see no data for our
79 # field, is it because the user has not yet submitted the form, or that they
80 # have submitted it with all the options unchecked? We will have to assume the
81 # latter, which basically means that you can't specify 'positive' defaults
84 return $request->getArray( $this->mName
, array() );
88 function getDefault() {
89 if ( isset( $this->mDefault
) ) {
90 return $this->mDefault
;
96 function filterDataForSubmit( $data ) {
97 $options = HTMLFormField
::flattenOptions( $this->mParams
[ 'options' ] );
100 foreach ( $options as $opt ) {
101 $res[ "$opt" ] = in_array( $opt, $data );
107 protected function needsLabel() {