Custom element to be used as the button for adding a new element, instead of the default plus icon.
The element you specify here will be removed from its position in the DOM and moved to the appropriate position below the repeated element.
Note:
repeat
option in the properties panel of the designer.For example, you can add a button element to the form and style it via CSS to your liking. Assuming the
button is named btnMyAwesomeAddButton
and should be used for the input field tfMail
, use the following
code:
$('[name="tfMail"]').dynamic({
addButton: $('[name="btnMyAwesomeAddButton"]'),
});
Custom element to be used as the button for removing a repeated element, instead of the default minus icon.
The element you specify here will be removed from its position in the DOM. Copies of that element are then added below each repeated element.
Note:
repeat
option in the properties panel of the designer.For example, you can add a button element to the form and style it via CSS to your liking. Assuming the
button is named btnMyAwesomeDelButton
and should be used for the input field tfMail
, use the following
code:
$('[name="tfMail"]').dynamic({
delButton: $('[name="btnMyAwesomeDelButton"]'),
});
This option lets you hide the add and remove buttons, in case the user should not be able to add or remove elements dynamically. The allowed values for this option are:
false
: All buttons are shown and can be used (the default)true
: Both the add and the remove buttons are hidden.[]
(no buttons are hidden), ["add"]
,
["delete"]
or ["add", "delete"]
.The maximum number of allowed repetitions. Default: 10.
The minimum number of allowed repetitions. Default: 1.
If specified, the value of this element is used as the number of dynamically created repeated elements.
Whenever the element's numerical value changes, elements are added or removed to reflect the new value.
Note:
repeat
option in the properties panel of the designer.For example, consider a repeated container with the details of a child, such as their name, birth of place
and sex. If you set the trigger to an input element tfNumberOfChildren
, there are always as many copies of
the child details container as entered number of children. Assuming the container is named divChild
, use
the following code:
$('[name="divChild"]').dynamic({
trigger: $('[name="tfNumberOfChildren"]'),
});
Optional callback function that is invoked after a new element repetition was added.
Event which triggered the addition of a new item.
The element that was added.
Optional callback function that is invoked after an element repetition was removed.
Note that this callback lets you to access the element that was removed. As it is already detached from the DOM, only certain properties such as its value and its children can still be accessed. Certain actions such as checking the element's visibility are not available anymore.
Event which triggered the removal.
The element that was removed.
Optional callback function that is invoked before a new element repetition is about to be added.
Note that this callback lets you to access the element before it was added. As it is not yet detached to the DOM, only certain properties such as its value and its children can be accessed. Certain actions such as checking the element's visibility are not yet available.
Event which triggered the addition of a new item.
The element that is about to be added.
If false
, the element will not be added. Otherwise, the element is added normally.
Optional callback function that is invoked before an element repetition is about to be removed.
Event which triggered the removal.
The item that is about to be removed.
If false
, the element will not be deleted. Otherwise the item is deleted.
A function that is invoked each time an element repetition is added or removed.
The current count of dynamically created items.
The item that was added or removed.
true
if the item was added, false
if it was removed.
A form element can be made repeatable by calling JQuery.dynamic on a form element. This is the configuration object that can optionally be passed to configure how many repetitions are allowed and much more.
Please note that you can also make an element repeatable by using the
repeat
option in the properties panel of the designer. You only need to use JavaScript in case you wish to make use of advanced features such as DynamicOptions.addButton or DynamicOptions.delButton.For example, to make an element repeatable and allow between 1 to 6 repetition:
$("[name='fsAddress']").dynamic({ minSize: 1, // At least 1 address maxSize: 6 // At most 6 addresses });