2017 © Pedro Peláez
 

yii2-extension yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

image

kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  • Thursday, October 19, 2017
  • by kartik-v
  • Repository
  • 15 Watchers
  • 82 Stars
  • 182,863 Installations
  • PHP
  • 43 Dependents
  • 0 Suggesters
  • 42 Forks
  • 23 Open issues
  • 17 Versions
  • 7 % Grown

The README.md

Krajee Logo
yii2-builder
Donate       kartikv

[![Latest Stable Version](https://poser.pugx.org/kartik-v/yii2-builder/v/stable)](https://packagist.org/packages/kartik-v/yii2-builder) [![Latest Unstable Version](https://poser.pugx.org/kartik-v/yii2-builder/v/unstable)](https://packagist.org/packages/kartik-v/yii2-builder) [![License](https://poser.pugx.org/kartik-v/yii2-builder/license)](https://packagist.org/packages/kartik-v/yii2-builder) [![Total Downloads](https://poser.pugx.org/kartik-v/yii2-builder/downloads)](https://packagist.org/packages/kartik-v/yii2-builder) [![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-builder/d/monthly)](https://packagist.org/packages/kartik-v/yii2-builder) [![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-builder/d/daily)](https://packagist.org/packages/kartik-v/yii2-builder)

A form builder extension that allows you to build both single view and multi-view/tabular forms for Yii Framework 2.0. The extension contains these widgets:, (*1)

  • Form
  • FormGrid
  • TabularForm

NOTE: Check the composer.json for this extension's requirements and dependencies., (*2)

Latest Release

Refer the CHANGE LOG for details on changes to various releases., (*3)

Docs & Demo

You can see detailed docs & demos and the API code documentation on usage of the extension., (*4)

Form

\kartik\builder\Form, (*5)

The Form Builder widget allows you to build a form through a configuration array. Key features available:, (*6)

  • Configure your form fields from a model extending yii\base\model or yii\db\ActiveRecord.
  • Ability to support various Bootstrap form layouts. Uses the advanced kartik\widgets\ActiveForm.
  • Use Bootstrap column/builder layout styling by just supplying columns property.
  • Build complex layouts (for example single, double, or multi columns in the same layout) - by reusing the widget for building your attributes.
  • Tweak ActiveForm defaults to control field options, styles, templates, and layouts.
  • Configure your own hints to display below each active field attribute.
  • Various Bootstrap styling features are available by default. However, one can easily customize and theme it to one's liking using any CSS framework.
  • Supports and renders HTML input types (uses kartik\widgets\ActiveField) including input widgets and more:
    • INPUT_TEXT or textInput
    • INPUT_TEXTAREA or textarea
    • INPUT_PASSWORD or passwordInput
    • INPUT_DROPDOWN_LIST or dropdownList
    • INPUT_LIST_BOX or listBox
    • INPUT_CHECKBOX or checkbox
    • INPUT_RADIO or radio
    • INPUT_CHECKBOX_LIST or checkboxList
    • INPUT_CHECKBOX_BUTTON_GROUP or checkboxList
    • INPUT_RADIO_LIST or radioList
    • INPUT_MULTISELECT or multiselect
    • INPUT_FILE or fileInput
    • INPUT_HTML5 or input
    • INPUT_WIDGET or widget
    • INPUT_HIDDEN or hiddenInput
    • INPUT_STATIC or staticInput
    • INPUT_HIDDEN_STATIC or hiddenStaticInput
    • INPUT_RAW or raw (any free text or html markup)

FormGrid

\kartik\builder\FormGrid, (*7)

Create bootstrap grid layouts in a snap. The Form Grid Builder widget offers an easy way to configure your form inputs as a bootstrap grid layout and a single array configuration. It basically uses multiple instances of the \kartik\builder\Form widget above to generate this grid. One needs to just setup the rows for the grid, where each row will be an array configuration as needed by the Form widget. However, most of the common settings like model, form, columns etc. can be defaulted at FormGrid widget level., (*8)

Tabular Form

kartik\builder\TabularForm, (*9)

The tabular form allows you to update information from multiple models (typically used in master-detail forms). Key features, (*10)

  • Supports all input types as mentioned in the Form builder widget
  • The widget works like a Yii GridView and uses an ActiveDataProvider to read the models information.
  • Supports features of the builderview like pagination and sorting.
  • Allows you to highlight and select table rows
  • Allows you to add and configure action buttons for each row.
  • Configure your own hints to display below each active field attribute.
  • Various Bootstrap styling features are available by default. However, one can easily customize and theme it to one's liking using any CSS framework.
  • Advanced table styling, columns, and layout configuration by using the features available in the kartik\builder\GridView and the kartik\widgets\ActiveForm widget.
  • One can easily read and manage the tabular input data using the loadMultiple and validateMultiple functions in yii\base\Model.

NOTE: The TabularForm widget depends on and uses the yii2-grid module. Hence, the gridview module needs to be setup in your Yii configuration file., (*11)

'modules' => [
   'gridview' =>  [
        'class' => '\kartik\grid\Module'
    ]
];

IMPORTANT: You must follow one of the two options to setup your DataProvider or your columns to ensure primary key for each record is properly identified. - Option 1 (preferred): Setup your dataProvider query to use indexBy method to index your records by primary key. For example:, (*12)

$query = Model::find()->indexBy('id'); // where `id` is your primary key

$dataProvider = new ActiveDataProvider([
    'query' => $query,
]);
  • Option 2 (alternate): You can setup the primary key attribute as one of your columns with a form input type (and hide if needed) - so that the models are appropriately updated via loadMultiple method (even if you reorder or sort the columns). You must also set this attribute to be safe in your model validation rules. This is been depicted in the example below.
'attributes'=>[
    'id'=>[ // primary key attribute
        'type'=>TabularForm::INPUT_HIDDEN, 
        'columnOptions'=>['hidden'=>true]
    ], 
 ]

Demo

You can see detailed documentation on usage of the extension., (*13)

Installation

The preferred way to install this extension is through composer., (*14)

Note: You must set the minimum-stability to dev in the composer.json file in your application root folder before installation of this extension., (*15)

Either run, (*16)

$ php composer.phar require kartik-v/yii2-builder "@dev"

or add, (*17)

"kartik-v/yii2-builder": "@dev"

to the require section of your composer.json file., (*18)

Usage

Form

use kartik\builder\Form;
$form = ActiveForm::begin();
echo Form::widget([
    'model' => $model,
    'form' => $form,
    'columns' => 2,
    'attributes' => [
        'username' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']],
        'password' => ['type'=>Form::INPUT_PASSWORD, 'options'=>['placeholder'=>'Enter password...']],
        'rememberMe' => ['type'=>Form::INPUT_CHECKBOX],
    ]
]);
ActiveForm::end();

FormGrid

use kartik\builder\Form;
use kartik\builder\FormGrid;
$form = ActiveForm::begin();
echo FormGrid::widget([
    'model' => $model,
    'form' => $form,
    'autoGenerateColumns' => true,
    'rows' => [
        [
            'attributes' => [
                'username' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']],
                'password' => ['type'=>Form::INPUT_PASSWORD, 'options'=>['placeholder'=>'Enter password...']],
                'rememberMe' => ['type'=>Form::INPUT_CHECKBOX],
            ],
        ],
        [
            'attributes' => [
                'first_name' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter first name...']],
                'last_name' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter last name...']],
            ]
        ]
    ]
]);
ActiveForm::end();

TabularForm

use kartik\builder\TabularForm;
$form = ActiveForm::begin();
echo TabularForm::widget([
    'bsVersion' => '4.x',
    'form' => $form,
    'dataProvider' => $dataProvider,
    'attributes' => [
        'name' => ['type' => TabularForm::INPUT_TEXT],
        'color' => [
            'type' => TabularForm::INPUT_WIDGET, 
            'widgetClass' => \kartik\widgets\ColorInput::classname()
        ],
        'author_id' => [
            'type' => TabularForm::INPUT_DROPDOWN_LIST, 
            'items'=>ArrayHelper::map(Author::find()->orderBy('name')->asArray()->all(), 'id', 'name')
        ],
        'buy_amount' => [
            'type' => TabularForm::INPUT_TEXT, 
            'options'=>['class'=>'form-control text-right'], 
            'columnOptions'=>['hAlign'=>GridView::ALIGN_RIGHT]
        ],
        'sell_amount' => [
            'type' => TabularForm::INPUT_STATIC, 
            'columnOptions'=>['hAlign'=>GridView::ALIGN_RIGHT]
        ],
    ],
    'gridSettings' => [
        'floatHeader' => true,
        'panel' => [
            'heading' => '<i class="fas fa-book"></i> Manage Books',
            'type' => GridView::TYPE_PRIMARY,
            'after'=> 
                Html::a(
                    '<i class="fas fa-plus"></i> Add New', 
                    $createUrl, 
                    ['class'=>'btn btn-success']
                ) . '&nbsp;' . 
                Html::a(
                    '<i class="fas fa-times"></i> Delete', 
                    $deleteUrl, 
                    ['class'=>'btn btn-danger']
                ) . '&nbsp;' .
                Html::submitButton(
                    '<i class="fas fa-save"></i> Save', 
                    ['class'=>'btn btn-primary']
                )
        ]
    ]     
]); 
ActiveForm::end(); 

License

yii2-builder is released under the BSD-3-Clause License. See the bundled LICENSE.md for details., (*19)

The Versions

19/10 2017

dev-master

9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 form widget builder

29/08 2017

v1.6.3

1.6.3.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 form widget builder

19/11 2016

v1.6.2

1.6.2.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 form widget builder

17/06 2015

v1.6.1

1.6.1.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 form widget builder

28/01 2015

v1.6.0

1.6.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

04/12 2014

1.5.0.x-dev

1.5.0.9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

04/12 2014

v1.5.0

1.5.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

01/12 2014

1.4.0.x-dev

1.4.0.9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

01/12 2014

v1.4.0

1.4.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

27/11 2014

1.3.0.x-dev

1.3.0.9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

27/11 2014

v1.3.0

1.3.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

11/11 2014

1.2.0.x-dev

1.2.0.9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

11/11 2014

v1.2.0

1.2.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

05/10 2014

1.1.0.x-dev

1.1.0.9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

05/10 2014

v1.1.0

1.1.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

11/06 2014

1.0.0.x-dev

1.0.0.9999999-dev https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder

11/06 2014

v1.0.0

1.0.0.0 https://github.com/kartik-v/yii2-builder

Build forms (single-row or multi-row/tabular) easily for Yii Framework 2.0

  Sources   Download

BSD 3-Clause

The Requires

 

extension yii2 form widget builder