Class yii\bootstrap4\ActiveField
Inheritance | yii\bootstrap4\ActiveField » yii\widgets\ActiveField |
---|
A Bootstrap 4 enhanced version of \yii\widgets\ActiveField.
This class adds some useful features to \yii\widgets\ActiveField to render all sorts of Bootstrap 4 form fields in different form layouts:
- $inputTemplate is an optional template to render complex inputs, for example input groups
- $horizontalCssClasses defines the CSS grid classes to add to label, wrapper, error and hint in horizontal forms
- inline()/inline() is used to render inline checkboxList() and radioList()
- $enableError can be set to
false
to disable to the error - $enableLabel can be set to
false
to disable to the label - label() can be used with a
bool
argument to enable/disable the label
There are also some new placeholders that you can use in the \yii\bootstrap4\template configuration:
{beginLabel}
: the opening label tag{labelTitle}
: the label title for use with{beginLabel}
/{endLabel}
{endLabel}
: the closing label tag{beginWrapper}
: the opening wrapper tag{endWrapper}
: the closing wrapper tag
The wrapper tag is only used for some layouts and form elements.
Note that some elements use slightly different defaults for \yii\bootstrap4\template and other options. You may want to override those predefined templates for checkboxes, radio buttons, checkboxLists and radioLists in the \yii\widgets\ActiveForm::fieldConfig of the \yii\widgets\ActiveForm:
- $checkTemplate the default template for checkboxes and radios
- $checkEnclosedTemplate the template for checkboxes and radios enclosed by label
Example:
use yii\bootstrap4\ActiveForm;
$form = ActiveForm::begin(['layout' => 'horizontal']);
// Form field without label
echo $form->field($model, 'demo', [
'inputOptions' => [
'placeholder' => $model->getAttributeLabel('demo'),
],
])->label(false);
// Inline radio list
echo $form->field($model, 'demo')->inline()->radioList($items);
// Control sizing in horizontal mode
echo $form->field($model, 'demo', [
'horizontalCssClasses' => [
'wrapper' => 'col-sm-2',
]
]);
// With 'default' layout you would use 'template' to size a specific field:
echo $form->field($model, 'demo', [
'template' => '{label} <div class="row"><div class="col-sm-4">{input}{error}{hint}</div></div>'
]);
// Input group
echo $form->field($model, 'demo', [
'inputTemplate' => '<div class="input-group"><span class="input-group-addon">@</span>{input}</div>',
]);
ActiveForm::end();
See also:
Public Properties
Public Methods
Protected Methods
Method | Description | Defined By |
---|---|---|
createLayoutConfig() | yii\bootstrap4\ActiveField | |
renderLabelParts() | yii\bootstrap4\ActiveField |
Property Details
The enclosed by label
template for checkboxes and radios in default layout
The template for checkboxes and radios in horizontal layout
The template for checkboxes and radios in default layout
Whether to render the error. Default is true
except for layout inline
.
Whether to render the label. Default is true
.
CSS grid classes for horizontal layout. This must be an array with these keys:
- 'offset' the offset grid class to append to the wrapper if no label is rendered
- 'label' the label grid class
- 'wrapper' the wrapper grid class
- 'error' the error grid class
- 'hint' the hint grid class
Whether to render checkboxList() and radioList() inline.
Optional template to render the {input}
placeholder content
Options for the wrapper tag, used in the {beginWrapper}
placeholder
Method Details
public void __construct ( $config = [] ) | ||
$config |
public void checkbox ( $options = [], $enclosedByLabel = false ) | ||
$options | ||
$enclosedByLabel |
public void checkboxList ( $items, $options = [] ) | ||
$items | ||
$options |
protected array createLayoutConfig ( $instanceConfig ) | ||
$instanceConfig | array | The configuration passed to this instance's constructor |
return | array | The layout specific default configuration for this instance |
---|
public void dropdownList ( $items, $options = [] ) | ||
$items | ||
$options |
public void fileInput ( $options = [] ) | ||
$options |
public $this inline ( $value = true ) | ||
$value | boolean | Whether to render a inline list |
return | $this | The field object itself Make sure you call this method before checkboxList() or radioList() to have any effect. |
---|
public void label ( $label = null, $options = [] ) | ||
$label | ||
$options |
public void listBox ( $items, $options = [] ) | ||
$items | ||
$options |
public void radio ( $options = [], $enclosedByLabel = false ) | ||
$options | ||
$enclosedByLabel |
public void radioList ( $items, $options = [] ) | ||
$items | ||
$options |
public void render ( $content = null ) | ||
$content |
protected void renderLabelParts ( $label = null, $options = [] ) | ||
$label | string|null | The label or null to use model label |
$options | array | The tag options |
Renders Bootstrap static form control.
See also https://getbootstrap.com/docs/4.2/components/forms/#readonly-plain-text.
public $this staticControl ( $options = [] ) | ||
$options | array | The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. There are also a special options:
|
return | $this | The field object itself |
---|