I''m creating my first Rails app and need an idea creating forms. I have Meeting model with place attribute. I want to have two fields for Meeting.place = one would be select with places from other meetings or text_field if the place is being used first time. User would be selecting radio_button of which field he has used. So is there any way to nest select and text_field within 2 radio_buttons? I would appreciate any other solution ideas too. Cheers -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Aug 9, 2011 at 5:49 AM, Jarek Plonski <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I want to have two fields for Meeting.place = one would be select with > places from other meetings or text_field if the place is being used > first time. User would be selecting radio_button of which field he has > used. > > So is there any way to nest select and text_field within 2 > radio_buttons?Why bother with the radio buttons? If there''s something in the text field use it; otherwise use the value from the select. (You''ll want to check that at least one has a value anyway.) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Why bother with the radio buttons? > > If there''s something in the text field use it; otherwise use the value > from > the select. (You''ll want to check that at least one has a value anyway.)Is it possible to check it in view or only in controller after submitting the form?? This one is only populating :place param from the last :place field = form_for @meeting do |f| ... .field = f.label :place = f.text_field :place .field = f.label :place = f.select :place, options_for_select(Meeting.places, params[:place]) .field = f.label :total_places = f.text_field :total_places .actions = f.submit ''Save'' I''m newbie and haven''t seen similar form in books. Other idea is to populate text from select box into text_field - how about that?? -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2011-Aug-09 15:04 UTC
Re: Re: Nesting select and text_field in radio_button
On Tue, Aug 9, 2011 at 7:53 AM, Jarek Plonski <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Is it possible to check it in view or only in controller after > submitting the form??You need that information in the controller, so might as well put the logic there (IMO).> This one is only populating :place param from the last :place fieldThe two form elements need to have different names. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 9, 2011, at 8:49 AM, Jarek Plonski wrote:> I''m creating my first Rails app and need an idea creating forms. > > I have Meeting model with place attribute. > > I want to have two fields for Meeting.place = one would be select with > places from other meetings or text_field if the place is being used > first time. User would be selecting radio_button of which field he has > used. > > So is there any way to nest select and text_field within 2 > radio_buttons? > > I would appreciate any other solution ideas too. > Cheers >Here''s how I usually solve this (requires Prototype, you''ll have to translate if you''re using jQuery): <script type="text/javascript> if($(''user_practice_id'')){ $(''user_practice_id'').options[$(''user_practice_id'').options.length] = new Option(''New...'',''New...''); $(''user_practice_id'').observe(''change'',function(evt){ if($F(this) == ''New...''){ var text_input = new Element(''input'', {type:''text'',size:''60'',name:''practice_name'',id:''practice_name''}); this.insert({before:text_input}); text_input.focus(); text_input[''_bak''] = $ (''user_practice_id'').hide().options.selectedIndex = 0; text_input.observe(''blur'',function(evt){ if($F(this) == '''' && this._bak){ this._bak.show(); this.remove(); } }); } }); } </script> In the controller, I test for the presence of the practice_name attribute, and if it''s there, create a new Practice before assigning the practice to the User. if( params[:practice_name] ) practice = Practice.create({:name => params[''practice_name'']}) params[:user][:practice_id] = practice.id end # regular save/update here This gets you a "combo-box", where you can choose, or add new, in one interface "slot". Walter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.