Download the PHP package yii2-extensions/dynamicform without Composer
On this page you can find all versions of the php package yii2-extensions/dynamicform. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yii2-extensions/dynamicform
More information about yii2-extensions/dynamicform
Files in yii2-extensions/dynamicform
Package dynamicform
Short Description Yii2 Dynamic form widget for cloning form elements in a nested manner while maintaining accessibility.
License BSD-3-Clause
Informations about the package dynamicform
Yii2 Extension for Making Dynamic Forms
It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Extension Usage
Databases
To explain usage of this extension we are going to have a sample scenario where we are building address book for customers. Each customer can have multiple addresses. See the image below for further details.
Models
With that database, our assumption is you have two models Customer
and Address
classes.
The Controller
1. Create Action
2. Update Action
The View
The View presents our complex form that will dynamically add or remove items. At the hear of it is the DynamicFormWidget
The following are some details on widget profperties:
widgetContainer
: Top container for the widget. Can only be alphanumeric plus a_
character. It is requiredwidgetBody
: The Container that hosts rows of form elements. Its value must conform to css class. It is requiredwidgetItem
: Represents single row of form line. If you are used to Bootstrap grid,widgetBody
is similar to a container andwidgetItem
to a row. It is a required element and must be in the format of css classlimit
: Maximum number of clones. It is an integer. Limits the number of times element can be cloned. Defaults to 999.min
: Minimum number of elements by default. Set it to 0 if you want empty sub-form elements or 1 to start with single row. Defaults to 1.insertButton
: Css class name for an element when clicked will add a row in the form.deleteButton
: Css class name for an element when clicked will delete a row in the form.model
: Sample model for the widget. If you are not sure, pass first element of the model rows. This requires your controller always send at least single model to the view.formId
: ID of yourActiveForm
. Mismatching the two is a recipe for disaster. Be careful!
Sample view
Javascript Events
Special Thanks
Special thanks to Wanderson Bragança for creating wonderful extension. We are here to make sure that his good work does not die. We are making our best to preserve his identity throughout the code he wrote.
Thank you Wanderson!
Check original work at https://github.com/wbraganca/yii2-dynamicform
Questions and Contributions
Contributions are welcome in form of PR. Please make a pull request to our github repository. You can ask a question or suggest a feature or file a bug using github issues.
Please star our repositories if you find them useful.
If you are on X, don't forget to connect with us at: @yiiframework for Yii Framework @yiiupdates for Yii News and Updates
All versions of dynamicform with dependencies
symfony/css-selector Version ^6.4||^7.0
symfony/dom-crawler Version ^6.4||^7.0