Form fields: parameters

* Can be used to specify extra options
* For now, allows support for multiple selection
This commit is contained in:
Emmanuel BENOîT 2016-01-03 10:49:47 +01:00
parent 90e09c35cd
commit b888e72eef
2 changed files with 13 additions and 1 deletions

View file

@ -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 )
{

View file

@ -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 ) {