Hi:
This one’s a little wierd. I have a simple form using form_for, it’s a
form for entering tasks. A few fields, no biggie. My submit button is
at the bottom of the page. I need to introduce the concept of sub-task.
The user can have one sub-task, or many sub-tasks. What I would really
like is a link or button that inserts a partial with another small form
for entering these subtasks. The number of subtasks that the user can
enter is variable and theoretically infinite.
Here’s the view:
<% form_for(:task, :url => tasks_path) do |f| %>
| Task Name * | <%= f.text_field :title %> | |
|
Task 1: Task 2: Task 3: |
<%= text_field_tag('step_1', 'enter Task 1 here', {}) %> <%= text_field_tag('step_1', 'enter Task 2 here', {}) %> <%= text_field_tag('step_1', 'enter Task 3 here', {}) %> <%= form_remote_tag :url => { :action => 'add_new' }, :html => { :id => 'addnew' } %> <%= link_to 'Add More Tasks', :method => 'add_new' %> <%= end_form_tag %> |
|
|
<%= submit_tag "Create" %> |
The controller code is complicated, but right now the “create” action
does what you would expect - simple insert.
I created a new method in the controller “add_new” but didn’t put
anything in it. I would imagine it needs code to add maybe the previous
sub-task.
Finally, i created a partial for the new tasks:
<%= text_field_tag(‘step’, ‘enter Task here’, {}) %>
and the RJS, again pretty standard:
page.insert_html :bottom, ‘addnew’, :partial => ‘add_new’
page.visual_effect :highlight, ‘addnew’
So, that’s it. When I click “add new task” the page refreshes but my
DIV isn’t populated and basically nothing happens.
Any help you can provide would be greatly appreciated.
Mike
