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

Reworked JS helpers with APi #17 #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 ! 👍

html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, override_partial).to_str).html_safe

link_to(name, '#', html_options)
content_tag :script, class: "association_template #{association}_template", type: "text/plain" do
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.

None yet

3 participants