0 follower

Final Class Yiisoft\Form\Field\Select

InheritanceYiisoft\Form\Field\Select » Yiisoft\Form\Field\Base\InputField » Yiisoft\Form\Field\Base\PartsField » Yiisoft\Form\Field\Base\BaseField » Yiisoft\Widget\Widget
ImplementsYiisoft\Form\Field\Base\EnrichFromValidationRules\EnrichFromValidationRulesInterface, Yiisoft\Form\Field\Base\ValidationClass\ValidationClassInterface
Uses TraitsYiisoft\Form\Field\Base\EnrichFromValidationRules\EnrichFromValidationRulesTrait, Yiisoft\Form\Field\Base\InputData\InputDataWithCustomNameAndValueTrait, Yiisoft\Form\Field\Base\ValidationClass\ValidationClassTrait

Represents <select> element that provides a menu of options.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Form\Field\Select
addContainerAttributes() Yiisoft\Form\Field\Base\BaseField
addContainerClass() Add one or more CSS classes to the container tag. Yiisoft\Form\Field\Base\BaseField
addErrorAttributes() Yiisoft\Form\Field\Base\PartsField
addErrorClass() Add one or more CSS classes to the error tag. Yiisoft\Form\Field\Base\PartsField
addHintAttributes() Yiisoft\Form\Field\Base\PartsField
addHintClass() Add one or more CSS classes to the hint tag. Yiisoft\Form\Field\Base\PartsField
addInputAttributes() Yiisoft\Form\Field\Base\InputField
addInputClass() Add one or more CSS classes to the input tag. Yiisoft\Form\Field\Base\InputField
addInputContainerAttributes() Yiisoft\Form\Field\Base\PartsField
addInputContainerClass() Add one or more CSS classes to the input container tag. Yiisoft\Form\Field\Base\PartsField
addLabelAttributes() Yiisoft\Form\Field\Base\PartsField
addLabelClass() Add one or more CSS classes to the label tag. Yiisoft\Form\Field\Base\PartsField
afterInput() Yiisoft\Form\Field\Base\PartsField
ariaDescribedBy() Identifies the element (or elements) that describes the object. Yiisoft\Form\Field\Select
ariaLabel() Defines a string value that labels the current element. Yiisoft\Form\Field\Select
autofocus() Focus on the control (put cursor into it) when the page loads. Only one form element could be in focus at the same time. Yiisoft\Form\Field\Select
beforeInput() Yiisoft\Form\Field\Base\PartsField
begin() Yiisoft\Form\Field\Base\BaseField
containerAttributes() Yiisoft\Form\Field\Base\BaseField
containerClass() Replace container tag CSS classes with a new set of classes. Yiisoft\Form\Field\Base\BaseField
containerId() Set container tag ID. Yiisoft\Form\Field\Base\BaseField
containerTag() Yiisoft\Form\Field\Base\BaseField
disabled() Yiisoft\Form\Field\Select
enrichFromValidationRules() Yiisoft\Form\Field\Base\EnrichFromValidationRules\EnrichFromValidationRulesTrait
error() Yiisoft\Form\Field\Base\PartsField
errorAttributes() Yiisoft\Form\Field\Base\PartsField
errorClass() Replace error tag CSS classes with a new set of classes. Yiisoft\Form\Field\Base\PartsField
errorConfig() Yiisoft\Form\Field\Base\PartsField
errorId() Set error tag ID. Yiisoft\Form\Field\Base\PartsField
form() Specifies the form element the tag input element belongs to. The value of this attribute must be the ID attribute of a form element in the same document. Yiisoft\Form\Field\Base\InputField
hideLabel() Yiisoft\Form\Field\Base\PartsField
hint() Yiisoft\Form\Field\Base\PartsField
hintAttributes() Yiisoft\Form\Field\Base\PartsField
hintClass() Replace hint tag CSS classes with a new set of classes. Yiisoft\Form\Field\Base\PartsField
hintConfig() Yiisoft\Form\Field\Base\PartsField
hintId() Set hint tag ID. Yiisoft\Form\Field\Base\PartsField
inputAttributes() Yiisoft\Form\Field\Base\InputField
inputClass() Replace input tag CSS classes with a new set of classes. Yiisoft\Form\Field\Base\InputField
inputContainerAttributes() Yiisoft\Form\Field\Base\PartsField
inputContainerClass() Replace input container tag CSS classes with a new set of classes. Yiisoft\Form\Field\Base\PartsField
inputContainerTag() Yiisoft\Form\Field\Base\PartsField
inputData() Yiisoft\Form\Field\Base\InputData\InputDataWithCustomNameAndValueTrait
inputId() Yiisoft\Form\Field\Base\InputField
inputInvalidClass() Set invalid CSS class for input tag. Yiisoft\Form\Field\Base\ValidationClass\ValidationClassTrait
inputValidClass() Set valid CSS class for input tag. Yiisoft\Form\Field\Base\ValidationClass\ValidationClassTrait
invalidClass() Set invalid CSS class. Yiisoft\Form\Field\Base\ValidationClass\ValidationClassTrait
items() Yiisoft\Form\Field\Select
label() Yiisoft\Form\Field\Base\PartsField
labelAttributes() Yiisoft\Form\Field\Base\PartsField
labelClass() Replace label tag CSS classes with a new set of classes. Yiisoft\Form\Field\Base\PartsField
labelConfig() Yiisoft\Form\Field\Base\PartsField
labelId() Set label tag ID. Yiisoft\Form\Field\Base\PartsField
multiple() Yiisoft\Form\Field\Select
name() Yiisoft\Form\Field\Base\InputData\InputDataWithCustomNameAndValueTrait
options() Yiisoft\Form\Field\Select
optionsData() Yiisoft\Form\Field\Select
prepareValue() Yiisoft\Form\Field\Base\InputData\InputDataWithCustomNameAndValueTrait
prompt() Yiisoft\Form\Field\Select
promptOption() Yiisoft\Form\Field\Select
render() Yiisoft\Form\Field\Base\BaseField
required() A boolean attribute. When specified, the element is required. Yiisoft\Form\Field\Select
shouldSetInputId() Yiisoft\Form\Field\Base\InputField
size() The size of the control. Yiisoft\Form\Field\Select
tabIndex() The tabindex attribute indicates that its element can be focused, and where it participates in sequential keyboard navigation (usually with the Tab key, hence the name). Yiisoft\Form\Field\Select
template() Set layout template for render a field. Yiisoft\Form\Field\Base\PartsField
templateBegin() Yiisoft\Form\Field\Base\PartsField
templateEnd() Yiisoft\Form\Field\Base\PartsField
token() Yiisoft\Form\Field\Base\PartsField
tokens() Yiisoft\Form\Field\Base\PartsField
unselectValue() Yiisoft\Form\Field\Select
useContainer() Yiisoft\Form\Field\Base\BaseField
validClass() Set valid CSS class. Yiisoft\Form\Field\Base\ValidationClass\ValidationClassTrait
validationRulesEnricher() Yiisoft\Form\Field\Base\EnrichFromValidationRules\EnrichFromValidationRulesTrait
value() Yiisoft\Form\Field\Base\InputData\InputDataWithCustomNameAndValueTrait

Constants

Hide inherited constants

Constant Value Description Defined By
BUILTIN_TOKENS [ '{input}', '{label}', '{hint}', '{error}', ] Yiisoft\Form\Field\Base\PartsField

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( )

                public function __construct()
{
    $this->select = SelectTag::tag();
}

            
addContainerAttributes() public method
public Yiisoft\Form\Field\Select addContainerAttributes ( array $attributes )
$attributes array

                final public function addContainerAttributes(array $attributes): static
{
    $new = clone $this;
    $new->containerAttributes = array_merge($new->containerAttributes, $attributes);
    return $new;
}

            
addContainerClass() public method

Defined in: Yiisoft\Form\Field\Base\BaseField::addContainerClass()

Add one or more CSS classes to the container tag.

public Yiisoft\Form\Field\Select addContainerClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function addContainerClass(?string ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->containerAttributes, $class);
    return $new;
}

            
addErrorAttributes() public method
public Yiisoft\Form\Field\Select addErrorAttributes ( array $attributes )
$attributes array

                final public function addErrorAttributes(array $attributes): static
{
    $new = clone $this;
    $new->errorAttributes = array_merge($new->errorAttributes, $attributes);
    return $new;
}

            
addErrorClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::addErrorClass()

Add one or more CSS classes to the error tag.

public Yiisoft\Form\Field\Select addErrorClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function addErrorClass(?string ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->errorAttributes, $class);
    return $new;
}

            
addHintAttributes() public method
public Yiisoft\Form\Field\Select addHintAttributes ( array $attributes )
$attributes array

                final public function addHintAttributes(array $attributes): static
{
    $new = clone $this;
    $new->hintAttributes = array_merge($new->hintAttributes, $attributes);
    return $new;
}

            
addHintClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::addHintClass()

Add one or more CSS classes to the hint tag.

public Yiisoft\Form\Field\Select addHintClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function addHintClass(?string ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->hintAttributes, $class);
    return $new;
}

            
addInputAttributes() public method
public Yiisoft\Form\Field\Select addInputAttributes ( array $attributes )
$attributes array

                final public function addInputAttributes(array $attributes): static
{
    $new = clone $this;
    $new->inputAttributes = array_merge($new->inputAttributes, $attributes);
    return $new;
}

            
addInputClass() public method

Defined in: Yiisoft\Form\Field\Base\InputField::addInputClass()

Add one or more CSS classes to the input tag.

public Yiisoft\Form\Field\Select addInputClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function addInputClass(?string ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->inputAttributes, $class);
    return $new;
}

            
addInputContainerAttributes() public method
public Yiisoft\Form\Field\Select addInputContainerAttributes ( array $attributes )
$attributes array

                final public function addInputContainerAttributes(array $attributes): static
{
    $new = clone $this;
    $new->inputContainerAttributes = array_merge($new->inputContainerAttributes, $attributes);
    return $new;
}

            
addInputContainerClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::addInputContainerClass()

Add one or more CSS classes to the input container tag.

public Yiisoft\Form\Field\Select addInputContainerClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function addInputContainerClass(?string ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->inputContainerAttributes, $class);
    return $new;
}

            
addInputValidationClassToAttributes() protected method
protected void addInputValidationClassToAttributes ( array &$attributes, Yiisoft\Form\Field\Base\InputData\InputDataInterface $inputData, boolean|null $hasCustomError null )
$attributes array
$inputData Yiisoft\Form\Field\Base\InputData\InputDataInterface
$hasCustomError boolean|null

                protected function addInputValidationClassToAttributes(
    array &$attributes,
    InputDataInterface $inputData,
    ?bool $hasCustomError = null,
): void {
    $this->addClassesToAttributes(
        $attributes,
        $inputData,
        $hasCustomError,
        $this->inputInvalidClass,
        $this->inputValidClass,
    );
}

            
addLabelAttributes() public method
public Yiisoft\Form\Field\Select addLabelAttributes ( array $attributes )
$attributes array

                final public function addLabelAttributes(array $attributes): static
{
    $new = clone $this;
    $new->labelAttributes = array_merge($new->labelAttributes, $attributes);
    return $new;
}

            
addLabelClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::addLabelClass()

Add one or more CSS classes to the label tag.

public Yiisoft\Form\Field\Select addLabelClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function addLabelClass(?string ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->labelAttributes, $class);
    return $new;
}

            
addValidationClassToAttributes() protected method
protected void addValidationClassToAttributes ( array &$attributes, Yiisoft\Form\Field\Base\InputData\InputDataInterface $inputData, boolean|null $hasCustomError null )
$attributes array
$inputData Yiisoft\Form\Field\Base\InputData\InputDataInterface
$hasCustomError boolean|null

                protected function addValidationClassToAttributes(
    array &$attributes,
    InputDataInterface $inputData,
    ?bool $hasCustomError = null,
): void {
    $this->addClassesToAttributes(
        $attributes,
        $inputData,
        $hasCustomError,
        $this->invalidClass,
        $this->validClass,
    );
}

            
afterInput() public method
public Yiisoft\Form\Field\Select afterInput ( string|\Stringable $content )
$content string|\Stringable

                final public function afterInput(string|Stringable $content): static
{
    $new = clone $this;
    $new->afterInput = $content;
    return $new;
}

            
ariaDescribedBy() public method

Identifies the element (or elements) that describes the object.

public self ariaDescribedBy ( string|null $value )
$value string|null

                public function ariaDescribedBy(?string ...$value): self
{
    $new = clone $this;
    $new->inputAttributes['aria-describedby'] = array_filter($value, static fn (?string $v): bool => $v !== null);
    return $new;
}

            
ariaLabel() public method

Defines a string value that labels the current element.

public self ariaLabel ( string|null $value )
$value string|null

                public function ariaLabel(?string $value): self
{
    $new = clone $this;
    $new->inputAttributes['aria-label'] = $value;
    return $new;
}

            
autofocus() public method

Focus on the control (put cursor into it) when the page loads. Only one form element could be in focus at the same time.

public self autofocus ( boolean $value true )
$value boolean

                public function autofocus(bool $value = true): self
{
    $new = clone $this;
    $new->inputAttributes['autofocus'] = $value;
    return $new;
}

            
beforeInput() public method
public Yiisoft\Form\Field\Select beforeInput ( string|\Stringable $content )
$content string|\Stringable

                final public function beforeInput(string|Stringable $content): static
{
    $new = clone $this;
    $new->beforeInput = $content;
    return $new;
}

            
beforeRender() protected method

protected void beforeRender ( )

                protected function beforeRender(): void
{
    if ($this->enrichFromValidationRules) {
        $this->enrichment = $this
            ->validationRulesEnricher
            ?->process($this, $this->getInputData()->getValidationRules())
            ?? [];
    }
}

            
begin() public method
public string|null begin ( )

                final public function begin(): ?string
{
    parent::begin();
    $this->isStartedByBegin = true;
    $this->beforeRender();
    $content = $this->generateBeginContent();
    return $this->renderOpenContainerAndContent($content);
}

            
containerAttributes() public method
public Yiisoft\Form\Field\Select containerAttributes ( array $attributes )
$attributes array

                final public function containerAttributes(array $attributes): static
{
    $new = clone $this;
    $new->containerAttributes = $attributes;
    return $new;
}

            
containerClass() public method

Defined in: Yiisoft\Form\Field\Base\BaseField::containerClass()

Replace container tag CSS classes with a new set of classes.

public Yiisoft\Form\Field\Select containerClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function containerClass(?string ...$class): static
{
    $new = clone $this;
    $new->containerAttributes['class'] = array_filter($class, static fn ($c) => $c !== null);
    return $new;
}

            
containerId() public method

Defined in: Yiisoft\Form\Field\Base\BaseField::containerId()

Set container tag ID.

public Yiisoft\Form\Field\Select containerId ( string|null $id )
$id string|null

Container tag ID.

                final public function containerId(?string $id): static
{
    $new = clone $this;
    $new->containerAttributes['id'] = $id;
    return $new;
}

            
containerTag() public method
public Yiisoft\Form\Field\Select containerTag ( string $tag )
$tag string

                final public function containerTag(string $tag): static
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->containerTag = $tag;
    return $new;
}

            
disabled() public method

public self disabled ( boolean $disabled true )
$disabled boolean

Whether select input is disabled.

                public function disabled(bool $disabled = true): self
{
    $new = clone $this;
    $new->inputAttributes['disabled'] = $disabled;
    return $new;
}

            
enrichFromValidationRules() public method
public self enrichFromValidationRules ( boolean $enrich true )
$enrich boolean

                public function enrichFromValidationRules(bool $enrich = true): self
{
    $new = clone $this;
    $new->enrichFromValidationRules = $enrich;
    return $new;
}

            
error() public method
public Yiisoft\Form\Field\Select error ( string|null $message, string $messages )
$message string|null
$messages string

                final public function error(?string $message, string ...$messages): static
{
    $new = clone $this;
    $new->errorConfig['message()'] = [$message, ...$messages];
    return $new;
}

            
errorAttributes() public method
public Yiisoft\Form\Field\Select errorAttributes ( array $attributes )
$attributes array

                final public function errorAttributes(array $attributes): static
{
    $new = clone $this;
    $new->errorAttributes = $attributes;
    $new->replaceErrorAttributes = true;
    return $new;
}

            
errorClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::errorClass()

Replace error tag CSS classes with a new set of classes.

public Yiisoft\Form\Field\Select errorClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function errorClass(?string ...$class): static
{
    $new = clone $this;
    $new->errorAttributes['class'] = $class;
    $new->replaceErrorClass = true;
    return $new;
}

            
errorConfig() public method
public Yiisoft\Form\Field\Select errorConfig ( array $config )
$config array

                final public function errorConfig(array $config): static
{
    $new = clone $this;
    $new->errorConfig = $config;
    return $new;
}

            
errorId() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::errorId()

Set error tag ID.

public Yiisoft\Form\Field\Select errorId ( string|null $id )
$id string|null

Error tag ID.

                final public function errorId(?string $id): static
{
    $new = clone $this;
    $new->errorAttributes['id'] = $id;
    return $new;
}

            
form() public method

Defined in: Yiisoft\Form\Field\Base\InputField::form()

Specifies the form element the tag input element belongs to. The value of this attribute must be the ID attribute of a form element in the same document.

public Yiisoft\Form\Field\Select form ( string|null $value )
$value string|null

                final public function form(?string $value): static
{
    $new = clone $this;
    $new->inputAttributes['form'] = $value;
    return $new;
}

            
generateBeginContent() protected method
protected string generateBeginContent ( )

                final protected function generateBeginContent(): string
{
    $parts = [
        '{input}' => $this->generateBeginInput(),
        '{label}' => ($this->hideLabel ?? $this->shouldHideLabel()) ? '' : $this->generateLabel(),
        '{hint}' => $this->generateHint(),
        '{error}' => $this->generateError(),
    ];
    return $this->makeContent($this->templateBegin, $parts);
}

            
generateBeginInput() protected method
protected string generateBeginInput ( )

                protected function generateBeginInput(): string
{
    return '';
}

            
generateContent() protected method
protected string|null generateContent ( )

                final protected function generateContent(): ?string
{
    $parts = [
        '{input}' => $this->generateInputContainerBegin()
            . $this->beforeInput
            . $this->generateInput()
            . $this->afterInput
            . $this->generateInputContainerEnd(),
        '{label}' => ($this->hideLabel ?? $this->shouldHideLabel()) ? '' : $this->generateLabel(),
        '{hint}' => $this->generateHint(),
        '{error}' => $this->generateError(),
    ];
    return $this->makeContent($this->template, $parts);
}

            
generateEndContent() protected method
protected string generateEndContent ( )

                final protected function generateEndContent(): string
{
    $parts = [
        '{input}' => $this->generateEndInput(),
        '{label}' => ($this->hideLabel ?? $this->shouldHideLabel()) ? '' : $this->generateLabel(),
        '{hint}' => $this->generateHint(),
        '{error}' => $this->generateError(),
    ];
    return $this->makeContent($this->templateEnd, $parts);
}

            
generateEndInput() protected method
protected string generateEndInput ( )

                protected function generateEndInput(): string
{
    return '';
}

            
generateInput() protected method

protected string generateInput ( )

                protected function generateInput(): string
{
    $value = $this->getValue();
    $multiple = $this->inputAttributes['multiple'] ?? false;
    if ($multiple) {
        $value ??= [];
        if (!is_iterable($value)) {
            throw new InvalidArgumentException(
                'Select field with multiple option requires iterable or null value.'
            );
        }
    } else {
        if (
            !is_scalar($value)
            && !$value instanceof Stringable
            && !$value instanceof BackedEnum
            && $value !== null
        ) {
            throw new InvalidArgumentException(
                'Non-multiple select field requires a string, Stringable, numeric, bool, backed enumeration or null value.'
            );
        }
        $value = $value === null ? [] : [$value];
    }
    /** @psalm-suppress MixedArgument We guess that enrichment contain correct values. */
    $selectAttributes = array_merge(
        $this->enrichment['inputAttributes'] ?? [],
        $this->getInputAttributes()
    );
    /** @psalm-var iterable<int, Stringable|scalar|BackedEnum> $value */
    return $this->select
        ->addAttributes($selectAttributes)
        ->name($this->getName())
        ->values($value)
        ->render();
}

            
getInputAttributes() protected method
protected array getInputAttributes ( )

                final protected function getInputAttributes(): array
{
    $attributes = $this->inputAttributes;
    $this->prepareIdInInputAttributes($attributes);
    $this->prepareInputAttributes($attributes);
    return $attributes;
}

            
getInputData() protected method
protected Yiisoft\Form\Field\Base\InputData\InputDataInterface getInputData ( )

                final protected function getInputData(): InputDataInterface
{
    if ($this->inputData === null) {
        $this->inputData = new InputData();
    }
    return $this->inputData;
}

            
getName() protected method
protected string|null getName ( )

                final protected function getName(): ?string
{
    return $this->useCustomName
        ? $this->customName
        : $this->getInputData()->getName();
}

            
getThemeConfig() protected static method
protected static array getThemeConfig ( string|null $theme )
$theme string|null

                final protected static function getThemeConfig(?string $theme): array
{
    return ThemeContainer::getTheme($theme)?->getFieldConfig(static::class) ?? [];
}

            
getValue() protected method
protected mixed getValue ( )

                final protected function getValue(): mixed
{
    $value = $this->useCustomValue
        ? $this->customValue
        : $this->getInputData()->getValue();
    return $this->prepareValueCallback === null
        ? $value
        : ($this->prepareValueCallback)($value);
}

            
hasCustomError() protected method
protected boolean hasCustomError ( )

                final protected function hasCustomError(): bool
{
    return isset($this->errorConfig['message()']);
}

            
hideLabel() public method
public Yiisoft\Form\Field\Select hideLabel ( boolean|null $hide true )
$hide boolean|null

                final public function hideLabel(?bool $hide = true): static
{
    $new = clone $this;
    $new->hideLabel = $hide;
    return $new;
}

            
hint() public method
public Yiisoft\Form\Field\Select hint ( string|null $content )
$content string|null

                final public function hint(?string $content): static
{
    $new = clone $this;
    $new->hintConfig['content()'] = [$content];
    return $new;
}

            
hintAttributes() public method
public Yiisoft\Form\Field\Select hintAttributes ( array $attributes )
$attributes array

                final public function hintAttributes(array $attributes): static
{
    $new = clone $this;
    $new->hintAttributes = $attributes;
    $new->replaceHintAttributes = true;
    return $new;
}

            
hintClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::hintClass()

Replace hint tag CSS classes with a new set of classes.

public Yiisoft\Form\Field\Select hintClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function hintClass(?string ...$class): static
{
    $new = clone $this;
    $new->hintAttributes['class'] = $class;
    $new->replaceHintClass = true;
    return $new;
}

            
hintConfig() public method
public Yiisoft\Form\Field\Select hintConfig ( array $config )
$config array

                final public function hintConfig(array $config): static
{
    $new = clone $this;
    $new->hintConfig = $config;
    return $new;
}

            
hintId() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::hintId()

Set hint tag ID.

public Yiisoft\Form\Field\Select hintId ( string|null $id )
$id string|null

Hint tag ID.

                final public function hintId(?string $id): static
{
    $new = clone $this;
    $new->hintAttributes['id'] = $id;
    return $new;
}

            
inputAttributes() public method
public Yiisoft\Form\Field\Select inputAttributes ( array $attributes )
$attributes array

                final public function inputAttributes(array $attributes): static
{
    $new = clone $this;
    $new->inputAttributes = $attributes;
    return $new;
}

            
inputClass() public method

Defined in: Yiisoft\Form\Field\Base\InputField::inputClass()

Replace input tag CSS classes with a new set of classes.

public Yiisoft\Form\Field\Select inputClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function inputClass(?string ...$class): static
{
    $new = clone $this;
    $new->inputAttributes['class'] = array_filter($class, static fn ($c) => $c !== null);
    return $new;
}

            
inputContainerAttributes() public method
public Yiisoft\Form\Field\Select inputContainerAttributes ( array $attributes )
$attributes array

                final public function inputContainerAttributes(array $attributes): static
{
    $new = clone $this;
    $new->inputContainerAttributes = $attributes;
    return $new;
}

            
inputContainerClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::inputContainerClass()

Replace input container tag CSS classes with a new set of classes.

public Yiisoft\Form\Field\Select inputContainerClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function inputContainerClass(?string ...$class): static
{
    $new = clone $this;
    $new->inputContainerAttributes['class'] = array_filter($class, static fn ($c) => $c !== null);
    return $new;
}

            
inputContainerTag() public method
public Yiisoft\Form\Field\Select inputContainerTag ( string|null $tag )
$tag string|null

                final public function inputContainerTag(?string $tag): static
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->inputContainerTag = $tag;
    return $new;
}

            
inputData() public method
public Yiisoft\Form\Field\Select inputData ( Yiisoft\Form\Field\Base\InputData\InputDataInterface $inputData )
$inputData Yiisoft\Form\Field\Base\InputData\InputDataInterface

                final public function inputData(InputDataInterface $inputData): static
{
    $new = clone $this;
    $new->inputData = $inputData;
    $new->useCustomName = false;
    $new->useCustomValue = false;
    return $new;
}

            
inputId() public method
public Yiisoft\Form\Field\Select inputId ( string|null $inputId )
$inputId string|null

                final public function inputId(?string $inputId): static
{
    $new = clone $this;
    $new->inputId = $inputId;
    return $new;
}

            
inputInvalidClass() public method
public self inputInvalidClass ( string|null $class )
$class string|null

                public function inputInvalidClass(?string $class): self
{
    $new = clone $this;
    $new->inputInvalidClass = $class;
    return $new;
}

            
inputValidClass() public method
public self inputValidClass ( string|null $class )
$class string|null

                public function inputValidClass(?string $class): self
{
    $new = clone $this;
    $new->inputValidClass = $class;
    return $new;
}

            
invalidClass() public method
public self invalidClass ( string|null $class )
$class string|null

                public function invalidClass(?string $class): self
{
    $new = clone $this;
    $new->invalidClass = $class;
    return $new;
}

            
items() public method

public self items ( \Yiisoft\Html\Tag\Optgroup|\Yiisoft\Html\Tag\Option $items )
$items \Yiisoft\Html\Tag\Optgroup|\Yiisoft\Html\Tag\Option

                public function items(Optgroup|Option ...$items): self
{
    $new = clone $this;
    $new->select = $this->select->items(...$items);
    return $new;
}

            
label() public method
public Yiisoft\Form\Field\Select label ( string|null $content )
$content string|null

                final public function label(?string $content): static
{
    $new = clone $this;
    $new->label = $content;
    return $new;
}

            
labelAttributes() public method
public Yiisoft\Form\Field\Select labelAttributes ( array $attributes )
$attributes array

                final public function labelAttributes(array $attributes): static
{
    $new = clone $this;
    $new->labelAttributes = $attributes;
    $new->replaceLabelAttributes = true;
    return $new;
}

            
labelClass() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::labelClass()

Replace label tag CSS classes with a new set of classes.

public Yiisoft\Form\Field\Select labelClass ( string|null $class )
$class string|null

One or many CSS classes.

                final public function labelClass(?string ...$class): static
{
    $new = clone $this;
    $new->labelAttributes['class'] = $class;
    $new->replaceLabelClass = true;
    return $new;
}

            
labelConfig() public method
public Yiisoft\Form\Field\Select labelConfig ( array $config )
$config array

                final public function labelConfig(array $config): static
{
    $new = clone $this;
    $new->labelConfig = $config;
    return $new;
}

            
labelId() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::labelId()

Set label tag ID.

public Yiisoft\Form\Field\Select labelId ( string|null $id )
$id string|null

Label tag ID.

                final public function labelId(?string $id): static
{
    $new = clone $this;
    $new->labelAttributes['id'] = $id;
    return $new;
}

            
multiple() public method

public self multiple ( boolean $value true )
$value boolean

Whether the user is to be allowed to select zero or more options.

                public function multiple(bool $value = true): self
{
    $new = clone $this;
    $new->inputAttributes['multiple'] = $value;
    return $new;
}

            
name() public method
public Yiisoft\Form\Field\Select name ( string|null $name )
$name string|null

                final public function name(?string $name): static
{
    $new = clone $this;
    $new->customName = $name;
    $new->useCustomName = true;
    return $new;
}

            
options() public method

public self options ( \Yiisoft\Html\Tag\Option $options )
$options \Yiisoft\Html\Tag\Option

                public function options(Option ...$options): self
{
    return $this->items(...$options);
}

            
optionsData() public method

public self optionsData ( array $data, boolean $encode true, array[] $optionsAttributes = [], array[] $groupsAttributes = [] )
$data array

Options data. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array.

Example: `php [

'1' => 'Santiago',
'2' => 'Concepcion',
'3' => 'Chillan',
'4' => 'Moscow'
'5' => 'San Petersburg',
'6' => 'Novosibirsk',
'7' => 'Ekaterinburg'

]; `

Example with options groups: `php [

'1' => [
    '1' => 'Santiago',
    '2' => 'Concepcion',
    '3' => 'Chillan',
],
'2' => [
    '4' => 'Moscow',
    '5' => 'San Petersburg',
    '6' => 'Novosibirsk',
    '7' => 'Ekaterinburg'
],

]; `

$encode boolean

Whether option content should be HTML-encoded.

$optionsAttributes array[]

Array of option attribute sets indexed by option values from {@see $data}.

$groupsAttributes array[]

Array of group attribute sets indexed by group labels from {@see $data}.

                public function optionsData(
    array $data,
    bool $encode = true,
    array $optionsAttributes = [],
    array $groupsAttributes = []
): self {
    $new = clone $this;
    $new->select = $this->select->optionsData($data, $encode, $optionsAttributes, $groupsAttributes);
    return $new;
}

            
prepareContainerAttributes() protected method

protected void prepareContainerAttributes ( array &$attributes )
$attributes array

                protected function prepareContainerAttributes(array &$attributes): void
{
    $this->addValidationClassToAttributes(
        $attributes,
        $this->getInputData(),
        $this->hasCustomError() ? true : null,
    );
}

            
prepareIdInInputAttributes() protected method
protected void prepareIdInInputAttributes ( array &$attributes )
$attributes array

                final protected function prepareIdInInputAttributes(array &$attributes): void
{
    $idFromTag = $attributes['id'] ?? null;
    if ($idFromTag !== null) {
        $this->inputIdFromTag = (string) $idFromTag;
    }
    if ($this->shouldSetInputId) {
        if ($this->inputId !== null) {
            $attributes['id'] = $this->inputId;
        } elseif ($idFromTag === null) {
            $attributes['id'] = $this->getInputData()->getId();
        }
    }
}

            
prepareInputAttributes() protected method

protected void prepareInputAttributes ( array &$attributes )
$attributes array

                protected function prepareInputAttributes(array &$attributes): void
{
    $this->addInputValidationClassToAttributes(
        $attributes,
        $this->getInputData(),
        $this->hasCustomError() ? true : null,
    );
}

            
prepareValue() public method
public Yiisoft\Form\Field\Select prepareValue ( callable|null $callback )
$callback callable|null

                final public function prepareValue(?callable $callback): static
{
    $new = clone $this;
    $new->prepareValueCallback = $callback;
    return $new;
}

            
prompt() public method

public self prompt ( string|null $text )
$text string|null

Text of the option that has dummy value and is rendered as an invitation to select a value.

                public function prompt(?string $text): self
{
    $new = clone $this;
    $new->select = $this->select->prompt($text);
    return $new;
}

            
promptOption() public method

public self promptOption ( \Yiisoft\Html\Tag\Option|null $option )
$option \Yiisoft\Html\Tag\Option|null

Option that has dummy value and is rendered as an invitation to select a value.

                public function promptOption(?Option $option): self
{
    $new = clone $this;
    $new->select = $this->select->promptOption($option);
    return $new;
}

            
render() public method
public string render ( )

                final public function render(): string
{
    if ($this->isStartedByBegin) {
        $this->isStartedByBegin = false;
        return $this->renderEnd();
    }
    $this->beforeRender();
    $content = $this->generateContent();
    if ($content === null) {
        $this->enrichment = [];
        return '';
    }
    $result = $this->renderOpenContainerAndContent($content);
    if ($this->useContainer) {
        $result .= "\n" . Html::closeTag($this->containerTag);
    }
    $this->enrichment = [];
    return $result;
}

            
renderError() protected method
protected string renderError ( Yiisoft\Form\Field\Part\Error $error )
$error Yiisoft\Form\Field\Part\Error

                final protected function renderError(Error $error): string
{
    return $error
        ->inputData($this->getInputData())
        ->render();
}

            
renderHint() protected method
protected string renderHint ( Yiisoft\Form\Field\Part\Hint $hint )
$hint Yiisoft\Form\Field\Part\Hint

                final protected function renderHint(Hint $hint): string
{
    return $hint
        ->inputData($this->getInputData())
        ->render();
}

            
renderLabel() protected method
protected string renderLabel ( Yiisoft\Form\Field\Part\Label $label )
$label Yiisoft\Form\Field\Part\Label

                final protected function renderLabel(Label $label): string
{
    $label = $label->inputData($this->getInputData());
    if ($this->shouldSetInputId === false) {
        $label = $label->useInputId(false);
    }
    if ($this->inputId !== null) {
        $label = $label->forId($this->inputId);
    } elseif ($this->inputIdFromTag !== null) {
        $label = $label->forId($this->inputIdFromTag);
    }
    return $label->render();
}

            
required() public method

A boolean attribute. When specified, the element is required.

public self required ( boolean $value true )
$value boolean

Whether the control is required for form submission.

                public function required(bool $value = true): self
{
    $new = clone $this;
    $new->inputAttributes['required'] = $value;
    return $new;
}

            
shouldHideLabel() protected method
protected boolean shouldHideLabel ( )

                protected function shouldHideLabel(): bool
{
    return false;
}

            
shouldSetInputId() public method
public Yiisoft\Form\Field\Select shouldSetInputId ( boolean $value )
$value boolean

                final public function shouldSetInputId(bool $value): static
{
    $new = clone $this;
    $new->shouldSetInputId = $value;
    return $new;
}

            
size() public method

The size of the control.

public self size ( integer|null $value )
$value integer|null

The number of options to show to the user.

                public function size(?int $value): self
{
    $new = clone $this;
    $new->inputAttributes['size'] = $value;
    return $new;
}

            
tabIndex() public method

The tabindex attribute indicates that its element can be focused, and where it participates in sequential keyboard navigation (usually with the Tab key, hence the name).

It accepts an integer as a value, with different results depending on the integer's value:

  • A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard navigation, but could be focused with Javascript or visually. It's mostly useful to create accessible widgets with JavaScript.
  • tabindex="0" means that the element should be focusable in sequential keyboard navigation, but its order is defined by the document's source order.
  • A positive value means the element should be focusable in sequential keyboard navigation, with its order defined by the value of the number. That is, tabindex="4" is focused before tabindex="5", but after tabindex="3".
public self tabIndex ( integer|null $value )
$value integer|null

                public function tabIndex(?int $value): self
{
    $new = clone $this;
    $new->inputAttributes['tabindex'] = $value;
    return $new;
}

            
template() public method

Defined in: Yiisoft\Form\Field\Base\PartsField::template()

Set layout template for render a field.

public Yiisoft\Form\Field\Select template ( string $template )
$template string

                final public function template(string $template): static
{
    $new = clone $this;
    $new->template = $template;
    return $new;
}

            
templateBegin() public method
public Yiisoft\Form\Field\Select templateBegin ( string $template )
$template string

                final public function templateBegin(string $template): static
{
    $new = clone $this;
    $new->templateBegin = $template;
    return $new;
}

            
templateEnd() public method
public Yiisoft\Form\Field\Select templateEnd ( string $template )
$template string

                final public function templateEnd(string $template): static
{
    $new = clone $this;
    $new->templateEnd = $template;
    return $new;
}

            
token() public method
public Yiisoft\Form\Field\Select token ( string $token, string|\Stringable $value )
$token string
$value string|\Stringable

                final public function token(string $token, string|Stringable $value): static
{
    $this->validateToken($token);
    $new = clone $this;
    $new->extraTokens[$token] = $value;
    return $new;
}

            
tokens() public method
public Yiisoft\Form\Field\Select tokens ( array $tokens )
$tokens array

                final public function tokens(array $tokens): static
{
    $new = clone $this;
    foreach ($tokens as $token => $value) {
        if (!is_string($token)) {
            throw new InvalidArgumentException(
                sprintf(
                    'Token should be string. %s given.',
                    get_debug_type($token),
                )
            );
        }
        if (!is_string($value) && !$value instanceof Stringable) {
            throw new InvalidArgumentException(
                sprintf(
                    'Token value should be string or Stringable. %s given.',
                    get_debug_type($value),
                )
            );
        }
        $this->validateToken($token);
        $new->extraTokens[$token] = $value;
    }
    return $new;
}

            
unselectValue() public method

public self unselectValue ( boolean|float|integer|string|\Stringable|null $value )
$value boolean|float|integer|string|\Stringable|null

                public function unselectValue(bool|float|int|string|Stringable|null $value): self
{
    $new = clone $this;
    $new->select = $this->select->unselectValue($value);
    return $new;
}

            
useContainer() public method
public Yiisoft\Form\Field\Select useContainer ( boolean $use )
$use boolean

                final public function useContainer(bool $use): static
{
    $new = clone $this;
    $new->useContainer = $use;
    return $new;
}

            
validClass() public method
public self validClass ( string|null $class )
$class string|null

                public function validClass(?string $class): self
{
    $new = clone $this;
    $new->validClass = $class;
    return $new;
}

            
validationRulesEnricher() public method
public self validationRulesEnricher ( Yiisoft\Form\ValidationRulesEnricherInterface|null $enricher )
$enricher Yiisoft\Form\ValidationRulesEnricherInterface|null

                public function validationRulesEnricher(?ValidationRulesEnricherInterface $enricher): self
{
    $new = clone $this;
    $new->validationRulesEnricher = $enricher;
    return $new;
}

            
value() public method
public Yiisoft\Form\Field\Select value ( mixed $value )
$value mixed

                final public function value(mixed $value): static
{
    $new = clone $this;
    $new->customValue = $value;
    $new->useCustomValue = true;
    return $new;
}