Sharon Machlis
2008-Sep-04 11:36 UTC
Can you use observe_field to watch a select list and then update the contents of a text field?
Before I waste more time trying to figure that out, I was wondering if it''s even possible? The Rails Way says that observe_field by default will trigger changes in text fields and text areas, and on clicks for radio buttons and check boxes. So perhaps I''m using the wrong tool here? Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-04 11:49 UTC
Re: Can you use observe_field to watch a select list and then update the contents of a text field?
On 4 Sep 2008, at 13:36, Sharon Machlis wrote:> > Before I waste more time trying to figure that out, I was wondering if > it''s even possible? The Rails Way says that observe_field by default > will trigger changes in text fields and text areas, and on clicks for > radio buttons and check boxes. So perhaps I''m using the wrong tool > here? Thanks.should do, but i''d just use an onChange handler. Fred> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sharon Machlis
2008-Sep-07 04:37 UTC
Re: Can you use observe_field to watch a select list and then update the contents of a text field?
So it''s easy enough to pop some :onchange JavaScript code inline for a collection_select drop-down list. That code adds value of what''s selected to a couple of other text fields: <label for="venue_id">Place*:</label> <%collection_select(:event, :venue_id, @venues_all, :id, :name, {:prompt => " Please select a location"}, {:onchange => "var id = this.value; document.forms[0].elements[2].value=(id);document.forms[0].elements[3].value=document.forms[0].elements[5].value"}) %> But I don''t want the venue value (id number) in the text fields; I want venue.phone and venue.url in those fields. After numerous hours the past few days, I still don''t understand how I can mix JavaScript and Ruby so I can access the venue.phone and venue.url values and have them update my form''s other text fields. Any advice appreciated. On Sep 4, 7:49 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4 Sep 2008, at 13:36,SharonMachliswrote: > > > > > Before I waste more time trying to figure that out, I was wondering if > > it''s even possible? The Rails Way says that observe_field by default > > will trigger changes in text fields and text areas, and on clicks for > > radio buttons and check boxes. So perhaps I''m using the wrong tool > > here? Thanks. > > should do, but i''d just use an onChange handler. > > Fred > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-07 10:13 UTC
Re: Can you use observe_field to watch a select list and then update the contents of a text field?
On Sep 7, 5:37 am, Sharon Machlis <smach...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So it''s easy enough to pop some :onchange JavaScript code inline for a > collection_select drop-down list. That code adds value of what''s > selected to a couple of other text fields: > > <label for="venue_id">Place*:</label> <%> collection_select(:event, :venue_id, @venues_all, :id, :name, {:prompt > => " Please select a location"}, {:onchange => "var id = this.value; > document.forms[0].elements[2].value=(id);document.forms[0].elements[3].valu e=document.forms[0].elements[5].value"}) > %> > > But I don''t want the venue value (id number) in the text fields; I > want venue.phone and venue.url in those fields. After numerous hours > the past few days, I still don''t understand how I can mix JavaScript > and Ruby so I can access the venue.phone and venue.url values and have > them update my form''s other text fields. Any advice appreciated.One way would be to make an ajax call from the on change handler. The remote_function helper is good for this. Something like remote_function( :url => {...}, :with => "''id=''+this.value") Should submit the selected id to the specified action. You can then you some rjs to update the appropriate form elements. Fred> > On Sep 4, 7:49 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 4 Sep 2008, at 13:36,SharonMachliswrote: > > > > Before I waste more time trying to figure that out, I was wondering if > > > it''s even possible? The Rails Way says that observe_field by default > > > will trigger changes in text fields and text areas, and on clicks for > > > radio buttons and check boxes. So perhaps I''m using the wrong tool > > > here? Thanks. > > > should do, but i''d just use an onChange handler. > > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---