Form fields: parameters
* Can be used to specify extra options * For now, allows support for multiple selection
This commit is contained in:
parent
90e09c35cd
commit
b888e72eef
2 changed files with 13 additions and 1 deletions
|
@ -19,6 +19,8 @@ final class Field
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
private $type;
|
private $type;
|
||||||
|
private $parameters;
|
||||||
|
|
||||||
private $options = array( );
|
private $options = array( );
|
||||||
|
|
||||||
private $description;
|
private $description;
|
||||||
|
@ -33,10 +35,11 @@ final class Field
|
||||||
private $errors = array( );
|
private $errors = array( );
|
||||||
|
|
||||||
|
|
||||||
public function __construct( $name , $type )
|
public function __construct( $name , $type , $parameters = array( ) )
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
$this->parameters = $parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,6 +70,12 @@ final class Field
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasParameter( $name )
|
||||||
|
{
|
||||||
|
return array_key_exists( $name , $this->parameters )
|
||||||
|
|| array_search( $name , $this->parameters ) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setDescription( $description )
|
public function setDescription( $description )
|
||||||
{
|
{
|
||||||
|
|
|
@ -106,6 +106,9 @@ class FieldView_Select
|
||||||
->setAttribute( 'name' , $field->name( ) )
|
->setAttribute( 'name' , $field->name( ) )
|
||||||
->setAttribute( 'id' , $prefix . 'field' )
|
->setAttribute( 'id' , $prefix . 'field' )
|
||||||
->setAttribute( 'class' , 'form-select' );
|
->setAttribute( 'class' , 'form-select' );
|
||||||
|
if ( $field->hasParameter( 'multiple' ) ) {
|
||||||
|
$select->setAttribute( 'multiple' , 'multiple' );
|
||||||
|
}
|
||||||
|
|
||||||
$selected = $field->value( );
|
$selected = $field->value( );
|
||||||
foreach ( $field->options( ) as $value => $obj ) {
|
foreach ( $field->options( ) as $value => $obj ) {
|
||||||
|
|
Loading…
Reference in a new issue