DynamicInputsFor v1.1.0 DynamicInputsFor View Source
Helpers to create HTML forms with nested fields that can be created and deleted dynamically from the client.
The functions in this module extend the functionality of Phoenix.HTML.Form.inputs_for/4 to
return the html of a form with nested fields grouped in HTML tags with a class called fields and
the necessary anchors to add javascript that allows to add more fields dynamically from the
client.
Link to this section Summary
Functions
Creates a button to add more nested fields to the fields generated with dynamic_inputs_for/5.
Creates a button to mark association for deletion. When the button is pressed, a hidden input
called delete is created and set to "true". For this button to work, it must be called within
the function that is passed to dynamic_inputs_for/5.
It works like Phoenix.HTML.Form.inputs_for/4, but it also returns an HTML tag with the
information needed to add and delete fields from the client. The template argument is used to
generate the new nested fields.
The dynamic_add_button/3 function generates the button to add the fields.
Link to this section Functions
Creates a button to add more nested fields to the fields generated with dynamic_inputs_for/5.
Creates a button to mark association for deletion. When the button is pressed, a hidden input
called delete is created and set to "true". For this button to work, it must be called within
the function that is passed to dynamic_inputs_for/5.
dynamic_inputs_for(form, association, template, options \\ [], fun)
View SourceIt works like Phoenix.HTML.Form.inputs_for/4, but it also returns an HTML tag with the
information needed to add and delete fields from the client. The template argument is used to
generate the new nested fields.
The dynamic_add_button/3 function generates the button to add the fields.
Options
:wrapper_tag- HTML tag name to wrap the fields.:wrapper_attrs- HTML attributes for the wrapper.:association_alias- the name to be used in the form to generate the id of the element that has the template and is used to generate the fields, defaults the name of the association. It is usable to avoid conflicts with repeated ids when an association is called several times or there are different associations with the same name.:only_mark_deleted- create an input calleddeletewith"true"value and add thedeleted-fieldsclass to the wrapper to choose how to handle after validation errors. By default when a group of nested inputs is deleted the content is deleted, to avoid HTML validations, it is hidden and the input calleddeletewith"true"value is created.
See Phoenix.HTML.Form.inputs_for/4 for other options.