Skip to content

Reworked JS helpers with APi #17 - #27

Open
kirs wants to merge 1 commit into
railsgsoc:masterfrom
kirs:experimental
Open

Reworked JS helpers with APi #17#27
kirs wants to merge 1 commit into
railsgsoc:masterfrom
kirs:experimental

Conversation

@kirs

@kirs kirs commented Dec 3, 2014

Copy link
Copy Markdown

@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

kirs commented Dec 3, 2014

Copy link
Copy Markdown
Author

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

@m-Peter

m-Peter commented Dec 3, 2014

Copy link
Copy Markdown

Well done @kirs ! 👍

Comment thread lib/active_form/view_helpers.rb Outdated

Copy link
Copy Markdown

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
Copy Markdown
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

kirs commented Dec 16, 2014

Copy link
Copy Markdown
Author

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