Class Yiisoft\FormModel\Field
| Inheritance | Yiisoft\FormModel\Field |
|---|
Field is a shortcut static factory to ease creation of fields of various builtin types.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_THEME | null | Yiisoft\FormModel\Field |
Method Details
Create a checkbox field.
| public static \Yiisoft\Form\Field\Checkbox checkbox ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function checkbox(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Checkbox {
return Checkbox::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create checkboxes list field.
| public static \Yiisoft\Form\Field\CheckboxList checkboxList ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function checkboxList(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): CheckboxList {
return CheckboxList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a date field.
| public static \Yiisoft\Form\Field\Date date ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function date(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Date {
return Date::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a local date and time field.
| public static \Yiisoft\Form\Field\DateTimeLocal dateTimeLocal ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function dateTimeLocal(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): DateTimeLocal {
return DateTimeLocal::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create an email field.
| public static \Yiisoft\Form\Field\Email email ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function email(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Email {
return Email::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create an error for a field.
| public static \Yiisoft\Form\Field\Part\Error error ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to create error for. |
| $property | string |
Model property name to create error for. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function error(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Error {
return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create errors summary field.
| public static \Yiisoft\Form\Field\ErrorSummary errorSummary ( Yiisoft\FormModel\FormModelInterface|null $formModel = null, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface|null |
Model to take errors from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function errorSummary(
?FormModelInterface $formModel = null,
array $config = [],
?string $theme = null,
): ErrorSummary {
$widget = ErrorSummary::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
if ($formModel !== null) {
$widget = $widget->errors(
$formModel->isValidated()
? $formModel->getValidationResult()->getErrorMessagesIndexedByProperty()
: []
);
}
return $widget;
}
Create a fieldset.
| public static \Yiisoft\Form\Field\Fieldset fieldset ( array $config = [], string|null $theme = null ) | ||
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function fieldset(array $config = [], ?string $theme = null): Fieldset
{
return Fieldset::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
}
Create a file upload field.
| public static \Yiisoft\Form\Field\File file ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function file(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): File {
return File::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a field hint.
| public static \Yiisoft\Form\Field\Part\Hint hint ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to create hint for. |
| $property | string |
Model property name to create hint for. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function hint(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Hint {
return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create an image.
| public static \Yiisoft\Form\Field\Image image ( string|null $url = null, array $config = [], string|null $theme = null ) | ||
| $url | string|null |
"src" of the image. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function image(?string $url = null, array $config = [], ?string $theme = null): Image
{
$field = Image::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
if ($url !== null) {
$field = $field->src($url);
}
return $field;
}
Create a field label.
| public static \Yiisoft\Form\Field\Part\Label label ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to create label for. |
| $property | string |
Model property name to create label for. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function label(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Label {
return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a number field.
| public static \Yiisoft\Form\Field\Number number ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function number(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Number {
return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a password field.
| public static \Yiisoft\Form\Field\Password password ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function password(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Password {
return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a radio list field.
| public static \Yiisoft\Form\Field\RadioList radioList ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function radioList(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): RadioList {
return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a range field.
| public static \Yiisoft\Form\Field\Range range ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function range(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Range {
return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a reset button.
| public static \Yiisoft\Form\Field\ResetButton resetButton ( string|null $content = null, array $config = [], string|null $theme = null ) | ||
| $content | string|null |
Button content. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function resetButton(
?string $content = null,
array $config = [],
?string $theme = null,
): ResetButton {
$field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
if ($content !== null) {
$field = $field->content($content);
}
return $field;
}
Create a select field.
| public static \Yiisoft\Form\Field\Select select ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function select(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Select {
return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a submit button.
| public static \Yiisoft\Form\Field\SubmitButton submitButton ( string|null $content = null, array $config = [], string|null $theme = null ) | ||
| $content | string|null |
Button content. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function submitButton(
?string $content = null,
array $config = [],
?string $theme = null,
): SubmitButton {
$field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
if ($content !== null) {
$field = $field->content($content);
}
return $field;
}
Create a phone number field.
| public static \Yiisoft\Form\Field\Telephone telephone ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function telephone(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Telephone {
return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a text field.
| public static \Yiisoft\Form\Field\Text text ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function text(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Text {
return Text::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a text area field.
| public static \Yiisoft\Form\Field\Textarea textarea ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function textarea(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Textarea {
return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a time field.
| public static \Yiisoft\Form\Field\Time time ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function time(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Time {
return Time::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Create a URL input field.
| public static \Yiisoft\Form\Field\Url url ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme = null ) | ||
| $formModel | Yiisoft\FormModel\FormModelInterface |
Model to take value from. |
| $property | string |
Model property name to take value from. |
| $config | array |
Widget config. |
| $theme | string|null |
Theme to use. If not specified, default theme is used. |
final public static function url(
FormModelInterface $formModel,
string $property,
array $config = [],
?string $theme = null,
): Url {
return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
->inputData(new FormModelInputData($formModel, $property));
}
Signup or Login in order to comment.