hi, i have a situation where i have a list of options from which a user selects his options if its not in the list he/she selects Others/Not Present and a new textfield should pop up and the data entered there should be considered instead of dropdown. i have done this using javascript/dhtml but i was wondering how this can be done using pure rails i.e using some of the RoR apis?. i would appreciate if anyone helps me with this. warm regards gaurav v bagga -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060618/1f85dd99/attachment.html
Gaurav, Observe field is really good for this. If you set an observe field on your select box, and leave out the frequency option it will perform the action on onchange. I think there is also an :on option that you can specify the event. It then becomes an rjs response (or inline render of the page object) to supply the text box with value etc. Hope this is what your after On 6/19/06, gaurav bagga <gaurav.v.bagga@gmail.com> wrote:> > hi, > > i have a situation where i have a list of options from which a user > selects his options if its not in the list he/she selects Others/Not Present > and a new textfield should pop up and the data entered there should be > considered instead of dropdown. > > i have done this using javascript/dhtml but i was wondering how this can > be done using pure rails i.e using some of the RoR apis?. > > i would appreciate if anyone helps me with this. > > warm regards > gaurav v bagga > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060618/6ae8d309/attachment.html
Daniel, thanks for your reply , but i have started RoR a week back and i am really new, what you said i didn''t get, well i will google around what you have said and try to find out the way regards gaurav On 6/19/06, Daniel N <has.sox@gmail.com> wrote:> > Gaurav, > > Observe field is really good for this. If you set an observe field on > your select box, and leave out the frequency option it will perform the > action on onchange. I think there is also an :on option that you can > specify the event. > > It then becomes an rjs response (or inline render of the page object) to > supply the text box with value etc. > > Hope this is what your after > > On 6/19/06, gaurav bagga <gaurav.v.bagga@gmail.com> wrote: > > > hi, > > i have a situation where i have a list of options from which a user > selects his options if its not in the list he/she selects Others/Not Present > and a new textfield should pop up and the data entered there should be > considered instead of dropdown. > > i have done this using javascript/dhtml but i was wondering how this can > be done using pure rails i.e using some of the RoR apis?. > > i would appreciate if anyone helps me with this. > > warm regards > gaurav v bagga > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060619/994c7ac2/attachment.html
Bharat Ahluwalia
2006-Jun-19 07:09 UTC
[Rails] RE: on change of drop down showing a new textfield
> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of > rails- > From: "gaurav bagga" <gaurav.v.bagga@gmail.com> > Subject: Re: [Rails] on change of drop down showing a new textfield > To: rails@lists.rubyonrails.org > Message-ID: > <6052ead90606182225w5325928eiab6d1a2202b26f20@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > Daniel, > thanks for your reply , > but i have started RoR a week back and i am really new, what > you said i > didn''t get, > well i will google around what you have said and try to find > out the wayObserve_field allows u to observe a text box and execute code on the server using ajax. Take a look at the tutorial here http://www.onlamp.com/pub/a/onlamp/2005/06/09/rails_ajax.html?page=2 Basically the code on the server can return anything back to you. It could be a list of things that you can display in an existing control or it could be javascript code that u could execute to show a new control. Hope that helps. Bharat
On 6/19/06, Bharat Ahluwalia <bharata@aditi.com> wrote:> > > > > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org > > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of > > rails- > > From: "gaurav bagga" <gaurav.v.bagga@gmail.com> > > Subject: Re: [Rails] on change of drop down showing a new textfield > > To: rails@lists.rubyonrails.org > > Message-ID: > > <6052ead90606182225w5325928eiab6d1a2202b26f20@mail.gmail.com> > > Content-Type: text/plain; charset="iso-8859-1" > > > > Daniel, > > thanks for your reply , > > but i have started RoR a week back and i am really new, what > > you said i > > didn''t get, > > well i will google around what you have said and try to find > > out the waySorry I didn''t make myself a little clearer. Sometimes I get a little carried away ;) A good overview of how to use observe_field is on the wiki at http://wiki.rubyonrails.com/rails/pages/How+to+make+a+real-time+search+box+with+the+Ajax+helpers Your original requirements would probably be better served by using a text_field_with_auto_complete. In your controller use auto_complete_for :object, :method Make sure that you have included <%= javascript_include_tag :defaults %> in your application controller or nothing will happen. And then in your view <%= text_field_with_auto_complete "customer", "name" %> This will give you a drop down box generated by javascirpt, that the user can select. It will update a drop down list while the user is in the text field, and will provide values based on what they type in. If they don''t want to select from the list, they can type in a new value. Then in your controller you use, (Assuming that the field is for a Customer name @customer = Customer.find_or_create_by_name( params[:customer][:name]) Hopefully this will be enough to get you started. There is good info on the rails wiki, on various blogs, and of course google. Cheers Observe_field allows u to observe a text box and execute code on the> server using ajax. > > Take a look at the tutorial here > http://www.onlamp.com/pub/a/onlamp/2005/06/09/rails_ajax.html?page=2 > > Basically the code on the server can return anything back to you. It > could be a list of things that you can display in an existing control or > it could be javascript code that u could execute to show a new control. > > Hope that helps. > > Bharat > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060619/24dfdf2a/attachment-0001.html
Philip Hallstrom
2006-Jun-20 18:34 UTC
[Rails] on change of drop down showing a new textfield
Something like this... <%= observe_field(''tournament_id'', :update => ''event_select'', :url => {:action => ''tournament_select''}) -%> <div id=''event_select''></div> Then just be sure you have a tournament_select method in your controller and that div will get updated with it''s content. -philip On Mon, 19 Jun 2006, gaurav bagga wrote:> Daniel, > thanks for your reply , > but i have started RoR a week back and i am really new, what you said i > didn''t get, > well i will google around what you have said and try to find out the way > > regards > gaurav > > On 6/19/06, Daniel N <has.sox@gmail.com> wrote: >> >> Gaurav, >> >> Observe field is really good for this. If you set an observe field on >> your select box, and leave out the frequency option it will perform the >> action on onchange. I think there is also an :on option that you can >> specify the event. >> >> It then becomes an rjs response (or inline render of the page object) to >> supply the text box with value etc. >> >> Hope this is what your after >> >> On 6/19/06, gaurav bagga <gaurav.v.bagga@gmail.com> wrote: >> >> > hi, >> >> i have a situation where i have a list of options from which a user >> selects his options if its not in the list he/she selects Others/Not >> Present >> and a new textfield should pop up and the data entered there should be >> considered instead of dropdown. >> >> i have done this using javascript/dhtml but i was wondering how this can >> be done using pure rails i.e using some of the RoR apis?. >> >> i would appreciate if anyone helps me with this. >> >> warm regards >> gaurav v bagga >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >