SelectField
extends BaseField
in package
SelectField class represents a select input field in a form.
It extends the BaseField class and provides functionality for creating dropdown selection fields with various options.
Table of Contents
Constants
- TYPE_SELECT : mixed = 'select'
Properties
- $attribute : string
- $model : Model
- $type : string
Methods
- __construct() : mixed
- Field constructor.
- __toString() : string
- Returns the HTML representation of the field including label, input and error message.
- options() : string
- Generates HTML option elements for a select field.
- renderInput() : string
- Render a select input field with options
Constants
TYPE_SELECT
public
mixed
TYPE_SELECT
= 'select'
Properties
$attribute
public
string
$attribute
$model
public
Model
$model
$type
public
string
$type
Methods
__construct()
Field constructor.
public
__construct(Model $model, string $attribute) : mixed
Parameters
- $model : Model
- $attribute : string
__toString()
Returns the HTML representation of the field including label, input and error message.
public
__toString() : string
Return values
stringoptions()
Generates HTML option elements for a select field.
public
options(array<string|int, mixed> $options) : string
Parameters
- $options : array<string|int, mixed>
-
An associative array of options where keys are values and values are labels.
Return values
string —The concatenated HTML option tags.
renderInput()
Render a select input field with options
public
renderInput() : string
This method generates the HTML for a
- Class attributes with error handling
- Value attributes from model properties
- option elements generated from model configuration
- Proper HTML structure with opening and closing tags
Return values
string —The rendered HTML for the select field