Ajax form wtihin a form? Being in nothingness?

Hi Mike,

Mike Dershowitz wrote:

What I would really like is a link or button that
inserts a partial with another small form for
entering these subtasks.

When I click "add new task" the page refreshes
but my DIV isn't populated and basically nothing

You can't have a form within a form. The W3C HTML spec says so. I had the same issue.

It is possible, quite easy actually, to render multiple forms on one page. I render one each for the new tasks, then one (empty) one that looks to the visitor like the normal submit button but doesn't submit anything - just moves them to another page.

Note that this solution will not degrade gracefully if the visitor has js disabled. I decided not to even allow the visitor to visit that portion of my site if they don't have js enabled. The alternative is to redirect them a 'crippled' version of the page. You'll need to think through what your site needs to do.

Best regards,

Hi Mike,

Thanks as usual for your help.

You're welcome.

Here's what I don't understand: how would you
actually submit the form on the top with a fake
submit button on the bottom that didn't do anything?

You don't. I use ajax (form_remote_tag, in my case) to submit each of items the visitor enters as they enter it.

At this time, we don't have
plans for no javascript degredation.

Then you probably want to take a real hard look at your approach. In the documentation, any method that mentions XMLHttpRequest requires js to be enabled on the browser if you intend to update anything in the page you're showing the visitor.


Sorry. You've lost me. Start over.

That won't work if there are validations that require the presence of
multiple attributes, or does it?


Hi Michael,

Michael Schuerig wrote:

That won't work if there are validations that
require the presence of multiple attributes, or
does it?

Lots of ways to handle it.

Object.save_with_validation(false) will let you handle it in the database once everything you need to validate has been entered. You have to track what's been entered, of course, and then either save with or without validation depending on what you want to do.


Mike Dershowitz wrote:

Bill Walton wrote:

Sorry. You've lost me. Start over.
You think you're lost! :slight_smile:

Ok, so, with your help I was able to get the following link_to in my viewer code to work:

<%= link_to_remote "Add another task", :update => 'new_task',
                        :url => { :action => 'add_new', :id => '1'} %>

the div I want to update into is right above this part of the view, so:

<div id="new_task"></div>
<%= link_to_remote "Add another task", :update => 'new_task',
                        :url => { :action => 'add_new', :id => '1'} %>

But! When I click my link, instead of the contents of my partial, as specified in my RJS, I get the Javascript jibberish inserted into my div, instead of just the HTML. The jibberish is in my previous post. My RJS hasn't changed, looks like:

page.insert_html :bottom, 'new_task', :partial => 'add_new'
page.visual_effect :highlight, 'new_task'

I know that this is at least somewhat working, becuase when I click the remote link (add another task) the div is filled with the jibbersh, and it also highlights, per the RJS.

That's where I am, is that more clear or is there something else I'm omitting?

Thanks again for all of your help!


Get rid of the :update in your link_to_remotes. If you are using RJS then you are telling the page what to update already so this is messing things up.

Matt Margolis