From fbd561638fed4324a4a0f36deafe7a6624b29139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 3 Jan 2016 14:44:22 +0100 Subject: [PATCH] Form fields - Multiple selection values --- includes/form/field_views.inc.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/form/field_views.inc.php b/includes/form/field_views.inc.php index 7817868..484d0d9 100644 --- a/includes/form/field_views.inc.php +++ b/includes/form/field_views.inc.php @@ -108,15 +108,22 @@ class FieldView_Select ->setAttribute( 'class' , 'form-select' ); if ( $field->hasParameter( 'multiple' ) ) { $select->setAttribute( 'multiple' , 'multiple' ); + $v = $field->value( ); + if ( is_array( $v ) ) { + $selected = array_fill_keys( $v , '' ); + } else { + $selected = array( ); + } + } else { + $selected = array( $field->value( ) => '' ); } - $selected = $field->value( ); foreach ( $field->options( ) as $value => $obj ) { $option = HTML::make( 'option' ) ->setAttribute( 'value' , $value ) ->setAttribute( 'disabled' , $obj->disabled ? 'disabled' : null ) ->appendText( $obj->text ); - if ( "$value" === "$selected" ) { + if ( array_key_exists( $value , $selected ) ) { $option->setAttribute( 'selected' , 'selected' ); } $select->appendElement( $option );