Javascript Dynamic Forms
Dynamic forms is a javascript library meant to help make normal HTML forms more dynamic.
Setup
Notes:
- The jQuery library is required
- The compiled versions for this library are under the directory
dist
.
Example
See the playground for a working example.
... Single Input: Add Remove Multi Input: Add Remove Single Input with Fill: Add Remove Multi Input with Fill: Add Remove ...
Usage Notes:
data-dynamic-form
sets up a form section to be made dynamic. This is the container where new rows will be placed.data-dynamic-form-template
defines the div as a template, and the value given is the id for the template. This div will be removed from the form to prevent it from being used as input.data-dynamic-form-add
defines a button that is used to create a new row.data-dynamic-form-remove
defines a button that is used to remove a row.data-dynamic-form-input-id-template
is used for naming of dynamically added rows. The value will be replaced with the id.data-dynamic-form-input-name
is used by the fill to fill the input field.
Input Naming
- If you supply data with
data-dynamic-form-fill
, the form will automatically create new rows with the data. - Any supplied rows with
data-dynamic-form-fill
will be added to the form with their id. - Any new rows will be given an id by a base 26 alphabet system: a,b,c,...aa,ab,ac....
Adding an observer
If you ever want to capture events such as creating/removing a new row, you will need to create an observer.
Here is an example:
......
- Whenever a row is created, the function
rowWasCreated
will be called. - Whenever a row is removed, the function
rowWasRemoved
will be called.