fgh151/yii2-form-fields Collection of form fields

extensionformfields

Yii2 form fields

Collection of form fields

Installation

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.

Usage

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:

  • text - input type text
  • email - input type email
  • number - input type number
  • textarea - text area
  • binaryCheckbox - single check box (for example agree field)
  • checkboxList - list check boxes with same name
  • checkboxListOther - list check boxes with same name and input text field
  • binaryRadio - single radio button
  • radioList - list of radio buttons
  • radioListOther - list of radio boxes with other text field
  • file - file input field

BinaryCheckbox - is binary field, for example agree field

Field type examples

checkboxList, checkboxListOther, radioList, radioListOther
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' => 'Другое'
]);

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



0.0.16 is the latest of 12 releases



MIT license
Stats
0 github stars & 2 github forks
0 downloads in the last day
4 downloads in the last 30 days
1417 total downloads