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.
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-03-21 15: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?
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-03-21 15:53
Lindsay Boyd 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
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-21 16:01
(Received via mailing list)
On Mar 21, 2006, at 15:24, Lindsay Boyd 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
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-21 16:09
(Received via mailing list)
On Mar 21, 2006, at 16:00, Xavier Noria 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
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-03-21 17:07
Xavier Noria wrote:
> Is observe_field then suitable for your needs?

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