Forum: Ruby on Rails Can RoR's AJAX helpers do this?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lindsay B. (Guest)
on 2006-03-21 16:24
Hi,

I want to type text into an input field then on enter, use AJAX to
update the value of an input field elsewhere on the screen.

'observe_field' allows me to watch a form field and dynamically update a
DIV. Is there a variation or other method to allow me to update a field
instead?
Lindsay B. (Guest)
on 2006-03-21 16:53
Lindsay B. wrote:
>Is there a variation or other method to allow me to update a field
> instead?

I have raw AJAX code that will do this. If there isn't a RoR helper to
provide this functionality, is there a recommended RoR approach to
embedding Javascript in an app?

thanks
Lindsay
Xavier N. (Guest)
on 2006-03-21 17:01
(Received via mailing list)
On Mar 21, 2006, at 15:24, Lindsay B. wrote:

> I want to type text into an input field then on enter, use AJAX to
> update the value of an input field elsewhere on the screen.
>
> 'observe_field' allows me to watch a form field and dynamically
> update a
> DIV. Is there a variation or other method to allow me to update a
> field
> instead?

Just for the record, note that it does not need to be a div, it
updates the content of any element with that id in that page. For
instance, to update the contents of some paragraph just assign an id
to it:

     <%= observe_field('foo', :url => { :action =>
'my_ajax_updater' }) %>
     <!-- ... and 100 lines below ... -->
     <p id="foo">...</p>

Inline elements can be changed directly or wrapped in ad-hoc spans as
well.

Is observe_field then suitable for your needs?

-- fxn
Xavier N. (Guest)
on 2006-03-21 17:09
(Received via mailing list)
On Mar 21, 2006, at 16:00, Xavier N. wrote:

>
> Just for the record, note that it does not need to be a div, it
> updates the content of any element with that id in that page. For
> instance, to update the contents of some paragraph just assign an
> id to it:
>
>     <%= observe_field('foo', :url => { :action =>
> 'my_ajax_updater' }) %>
>     <!-- ... and 100 lines below ... -->
>     <p id="foo">...</p>

Oh sorry, that would be

     <%=
       observe_field(
         'my_field',
         :url => { :action => 'my_ajax_updater' },
         :update => 'foo'
       )
     %>
     <!-- ... and 100 lines below ... -->
     <p id="foo">...</p>

-- fxn
Lindsay B. (Guest)
on 2006-03-21 18:07
Xavier N. wrote:
> Is observe_field then suitable for your needs?

Yes, it is. Thanks Xavier!
This topic is locked and can not be replied to.