mamespalmero / dynamic_inputs_for Goto Github PK
View Code? Open in Web Editor NEWDynamically add/remove nested fields to your Phoenix forms
License: MIT License
Dynamically add/remove nested fields to your Phoenix forms
License: MIT License
For some reason when rendering delete button with a content different from simple text it stop working.
Working example:
<%= dynamic_delete_button(class: "text-gray-400 hover:text-gray-700") do %>
delete
<% end %>
Not working example:
<%= dynamic_delete_button(class: "text-gray-400 hover:text-gray-700") do %>
<div>delete</div>
<% end %>
I found this because I was trying to rendering a icon inside the button and it stop working. Probably related with JS selectors in the code?
Didn't test but probably the same is happening with the add button. The same problem is happening to the add button too.
Hello!
Is it possible to use your library with an embeds_many
? I'm trying to use it in a LiveView live_modal
, with deletions enabled by the virtual field method described in the README. This is what I have in the form_component.html.leex
template:
<%= dynamic_inputs_for f, :items, %Item{title: "", content: ""}, fn item -> %>
<%= text_input item, :title %>
<%= text_input item, :content %>
<%= dynamic_delete_button "Remove" %>
<%= error_tag answer, :content %>
<% end %>
<%= dynamic_add_button :items, "Add" %>
If I add an item, save the form, then remove the item, everything works fine. However, if I add an item, remove it and only then try to save the form, I get this error:
** (RuntimeError) cannot delete related %Item{title: "", content: "", delete: nil, id: nil} because it already exists and it is not currently associated with the given struct. Ecto forbids casting existing records through the association field for security reasons. Instead, set the foreign key value accordingly
I suppose the fix would be to actually delete the field if it wasn't already saved, I just don't know how to do it.
Thanks a lot for creating this library!
The current documentation suggests that all one needs to do to use the library is to add it to the mix.exs, but to have access to the functions in a template, I needed to import the library in my views.
This can be done globally by adding
import DynamicInputsFor
in view_helpers
in lib/<project-name>_web.ex
, or as mentioned before, in any view that renders templates using the library.
Maybe document that one could also just use <%= DynamicInputsFor.dynamic_add_button :options, "Add Option" %>
as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.