Nesting select and text_field in radio_button

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

On Tue, Aug 9, 2011 at 5:49 AM, Jarek P. [email protected]
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 S. ------------------------ [email protected]

twitter: @hassan

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??

On Tue, Aug 9, 2011 at 7:53 AM, Jarek P. [email protected]
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 field

The two form elements need to have different names.


Hassan S. ------------------------ [email protected]

twitter: @hassan

On Aug 9, 2011, at 8:49 AM, Jarek P. wrote:

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> <p>In the controller, I test for the presence of the practice_name<br> attribute, and if it’s there, create a new Practice before assigning<br> the practice to the User.</p> <pre><code> if( params[:practice_name] ) practice = Practice.create({:name => params['practice_name']}) params[:user][:practice_id] = practice.id end # regular save/update here </code></pre> <p>This gets you a “combo-box”, where you can choose, or add new, in one<br> interface “slot”.</p> <p>Walter</p>