Git Product home page Git Product logo

dynamic_inputs_for's People

Contributors

dabaer avatar maartenvanvliet avatar mamespalmero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dynamic_inputs_for's Issues

Working with embeds_many

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!

Delete button not clickable when content is different from text

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.

Document need for importing the library in a view

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.