Skip to content

Conversation

kirs
Copy link

@kirs kirs commented Dec 3, 2014

@dfyx noticed that there is no way to add new fields in JS without using buttons.
Here is my implementation (may not work yet on edge cases) with an API:

$(".task_list").addFormField("tasks") # receives association name, .task_list is container with fields
$(".task_list").removeFormField("tasks", 2) // destroys second field in the form

Example of form code can be found here: https://github.com/kirs/activeform/blob/e9375a9d6fac5e0e9ff893dc30e22e2e8bb112dd/test/dummy/app/views/assignments/_form.html.erb

@kirs
Copy link
Author

kirs commented Dec 3, 2014

Probably needs some client-side code review. Are we OK with shipping the code as jQuery plugin?

@m-Peter
Copy link

m-Peter commented Dec 3, 2014

Well done @kirs ! 👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't inserting a script element break turbolinks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first idea was to create a hidden div with content, but as my colleague told script is better than div because it's not rendering in DOM.
We can also use the template tag from HTML5 instead of script.

@kirs kirs force-pushed the experimental branch 3 times, most recently from e34172a to cb5fa96 Compare December 16, 2014 10:27
@kirs
Copy link
Author

kirs commented Dec 16, 2014

Done. If we're ok with implementation, let's merge it. @m-Peter @kaspth @guilleiguaran

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

Successfully merging this pull request may close these issues.

3 participants