From b888e72eef4e3f394b3fbcd13e2aaed298d1c8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 3 Jan 2016 10:49:47 +0100 Subject: [PATCH] Form fields: parameters * Can be used to specify extra options * For now, allows support for multiple selection --- includes/form/field.inc.php | 11 ++++++++++- includes/form/field_views.inc.php | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/includes/form/field.inc.php b/includes/form/field.inc.php index 289a915..e1d6df5 100644 --- a/includes/form/field.inc.php +++ b/includes/form/field.inc.php @@ -19,6 +19,8 @@ final class Field private $name; private $type; + private $parameters; + private $options = array( ); private $description; @@ -33,10 +35,11 @@ final class Field private $errors = array( ); - public function __construct( $name , $type ) + public function __construct( $name , $type , $parameters = array( ) ) { $this->type = $type; $this->name = $name; + $this->parameters = $parameters; } @@ -67,6 +70,12 @@ final class Field return $this->type; } + public function hasParameter( $name ) + { + return array_key_exists( $name , $this->parameters ) + || array_search( $name , $this->parameters ) !== false; + } + public function setDescription( $description ) { diff --git a/includes/form/field_views.inc.php b/includes/form/field_views.inc.php index c661175..7817868 100644 --- a/includes/form/field_views.inc.php +++ b/includes/form/field_views.inc.php @@ -106,6 +106,9 @@ class FieldView_Select ->setAttribute( 'name' , $field->name( ) ) ->setAttribute( 'id' , $prefix . 'field' ) ->setAttribute( 'class' , 'form-select' ); + if ( $field->hasParameter( 'multiple' ) ) { + $select->setAttribute( 'multiple' , 'multiple' ); + } $selected = $field->value( ); foreach ( $field->options( ) as $value => $obj ) {