Ajax insertion into a form


#1

After an ajax insertion in the dom, it seems the browser don’t
refresh its knowledge of the page.

The source of the page is identical after the insertion, whereas the
display is correct.

The ajax insertion is used to add an input field. The added fields
are ignored by the submission of the form.

Isn’t it possible to do that, or maybe there’s a problem in my code ?

The view :

new.rhtml
<%= start_form_tag :action => ‘create’ %>
<%= render_partial ‘form’ %>

Telephone

<%= link_to_remote("Add a number",
                    :url=>{:action=>'new_tel'},
                     :update =>'telephone', :position=> :after)
 %>
<br/>

<%= text_field_tag ‘telephone’ %>


<%= submit_tag “Create” %>
<%= end_form_tag %>

The controller :
def new
session[:num_tels]=0
end

def new_tel
@tel_num=session[:num_tels]
@tel_num=@tel_num.succ
session[:num_tels]=@tel_num
render (:text=>"
"+@tel_num.to_s+’<input
id=“telephone”’+@tel_num.to_s+’ name=“telephone”+@tel_num.to_s
type=“text” />’)
end


#2

You mean that the display of your page changes as expected, but when
you do a “view source”, the new input field isnt visible in the
source?

The browser’s “view source” will display the page source as
downloaded, and not as inferred from the DOM. If you want to view an
HTML version of the current DOM (say, after your AJAX update), I
recommend the Aardvark plugin for firefox. It lets you select any
container on the page (like your form element), and view its source as
inferred from the DOM.

cheers
Gerret


#3

Le 2 févr. 06 à 11:01, Gerret A. a écrit :

Thanks, great tool ! And of course the glitch was in my code ^^
http://www.karmatics.com/aardvark/


#4

Man, I was sooooo looking foward to this Aardvark plug-in.
However, it appears it is not compatible with FF 1.5.0.1 (which my FF
was
automatically updated with last night).

:frowning:

Oh well, maybe soon???

~damon


#5

Hi Damon,

Here is a great firefox extension for viewing the rendered source.

http://jennifermadden.com/scripts/ViewRenderedSource.html

Also if you want to see your ajax requests, it would suggest Julien
Couvreur’s greasemonkey script at:

http://blog.monstuff.com/archives/images/XMLHttpRequestDebugging.v1.2.user.js

Hope this can help out,
Eric

Damon H. wrote:

On 2/2/06, Pierre Gambarotto <removed_email_address@domain.invalid
> The browser’s “view source” will display the page source as

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Eric G.
http://www.ericgoodwin.com