Collection of form fields
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fgh151/yii2-form-fields "*"
or add
"fgh151/yii2-form-fields": "*"
to the require section of your composer.json
file.
Once the extension is installed, simply use it in your code by :
$form = ActiveForm::begin();
echo \fgh151\fields\InputWidget::widget([
'model' => $model,
'attribute' => 'attributeName',
'type' => \fgh151\fields\FieldTypes::getByName('text'), //default text
]);
ActiveForm::end();
Input without model
echo \fgh151\fields\InputWidget::widget([
'model' => new \yii\base\DynamicModel(['attributeName']),
'attribute' => 'attributeName',
]);
Input with custom label and value
echo \fgh151\fields\InputWidget::widget([
'model' => new \yii\base\DynamicModel(['attributeName']),
'attribute' => 'attributeName',
'options' => [
'label' => 'Custom label',
'value' => 'Some value',
]
]);
Available field types:
BinaryCheckbox - is binary field, for example agree field
echo \fgh151\fields\InputWidget::widget([
'model' => new \yii\base\DynamicModel(['FirstName']),
'attribute' => 'FirstName',
'type' => 6, //You can specify direct see \fgh151\fields\FieldTypes
'options' => [
'variants' => [
['label' => 'var1', 'value' => 'var1'],
['label' => 'var2', 'value' => 'var2'],
['label' => 'var3', 'value' => 'var3'],
]
]
]);
for 'other' label you can pass custom text:
echo \fgh151\fields\InputWidget::widget([
'model' => new \yii\base\DynamicModel(['FirstName']),
'attribute' => 'FirstName',
'type' => 6, //You can specify direct see \fgh151\fields\FieldTypes
'options' => [
'variants' => [
['label' => 'var1', 'value' => 'var1'],
['label' => 'var2', 'value' => 'var2'],
['label' => 'var3', 'value' => 'var3'],
]
],
'otherText' => 'Другое'
]);
Comments