Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/remove nested fields dynamically without links #17

Open
dfyx opened this issue Nov 17, 2014 · 5 comments
Open

Add/remove nested fields dynamically without links #17

dfyx opened this issue Nov 17, 2014 · 5 comments

Comments

@dfyx
Copy link

dfyx commented Nov 17, 2014

It would be cool if you could provide an easy way to add and remove fields directly through JS. A while ago I tried modifying nested_form to support this but ran into some problems related to rendering the fields.

I have a particular use case for this. I'm developing a management system for small conventions where the guests do certain chores like cooking and washing the dishes. For every day I want to enter how many people are needed for a given chore (on the first day there's no need to wash the dishes in the morning, on the last day there's no dinner).

So my idea was to have a change handler for the convention's begins_at and ends_at input fields and manipulate the form accordingly. Sadly I haven't found a good way to do that yet.

@kirs
Copy link

kirs commented Nov 26, 2014

Thanks for suggesting, I'll work on it.

@kirs
Copy link

kirs commented Nov 26, 2014

Here is the "add button" code:

<a class="add_fields" data-association-insertion-template="<div class=&quot;nested-fields&quot;>
  <div class=&quot;field&quot;>
    <label class=&quot;string optional&quot; for=&quot;assignment_tasks_attributes_new_tasks_task&quot;>Task</label><br>
    <input id=&quot;assignment_tasks_attributes_new_tasks_name&quot; name=&quot;assignment[tasks_attributes][new_tasks][name]&quot; type=&quot;text&quot; />
    <a class=&quot;remove_fields dynamic&quot; href=&quot;#&quot;>Delete</a>
  </div>
</div>" data-association="tasks" href="#">Add a Task</a>

The problem is that the template is inside the button, we need to find some way to store it in another place to be able to remove the button.

@m-Peter
Copy link

m-Peter commented Nov 27, 2014

I don't quite understand what is the desired functionality here :( . I could also help if someone explains it.

@dfyx
Copy link
Author

dfyx commented Nov 27, 2014

I want to trigger the functionality of add/remove links from arbitrary JavaScript like for example a change handler. (without having the actual links in my markup)

@kirs
Copy link

kirs commented Dec 3, 2014

Here is the progress: #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants