# "Choose from These Options, or Create a New Option"

**URL:** <https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909>\
**Category:** Rails\
**Created:** [August 24, 2007, 11:51am UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909 "2007-08-24T11:51:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 24, 2007, 11:51am UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/1 "2007-08-24T11:51:05Z")

</div>

Let’s say I have a dropdown selection list of existing teachers. The  
user can (1) select any one teacher, or (2) create a new one.

How would you tackle something like that?

I’m thinking what I could do is check if there’s any data inputted into  
the “new teacher” field – and if there is, create a new teacher. But,  
the issue with that is the user might also have an existing teacher  
highlighted, so that creates confusion – (not to mention bad  
usability!)

Based on your supreme knowledge, how would you approach something like  
this?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 24, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/2 "2007-08-24T12:03:22Z")

</div>

Bob S. wrote:

> Based on your supreme knowledge, how would you approach something like  
> this?

I don’t think you should allow people to create new teachers this way -  
you need to control the quality of people who teach the future!! 🙂

But seriously, I’ve given the same thing some thought for one of my  
applications (and haven’t yet implemented anything for it) but in my  
opinion, there are a couple of main ways to do it:

1. Have an option for ‘Other (enter below):’ and the person has to  
select that option and enter a name in the new teacher box.

2. Use Javascript & AJAX that if such an option is selected, it darkens  
out some of the screen and shows a div that allows you to create a new  
teacher record and then updates the select box.

3. Have a checkbox that allows you to create a new teacher. When the  
user checks it, the drop down select list is hidden and a new field is  
shown for creating a teacher.

What do you think?

Cheers,  
Mohit.  
8/24/2007 | 6:01 PM.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 24, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/3 "2007-08-24T17:41:20Z")

</div>

> Let’s say I have a dropdown selection list of existing teachers. The  
> user can (1) select any one teacher, or (2) create a new one.
> 
> How would you tackle something like that?
> 
> I’m thinking what I could do is check if there’s any data inputted into  
> the “new teacher” field – and if there is, create a new teacher. But,  
> the issue with that is the user might also have an existing teacher  
> highlighted, so that creates confusion – (not to mention bad  
> usability!)

You could use auto\_complete\_field to have a simple text field. They  
type  
in the name, it pulls up a list. If they don’t like one of those  
options,  
they finish typing and (assuming you only need the teacher’s name) you  
create a new teacher record when they submit the form.

If you need more information, I’d have a “Other/New” option in the  
select  
box, and have it overlay a div asking for that info like the other  
poster  
suggested.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 26, 2007, 11:06am UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/4 "2007-08-26T11:06:10Z")

</div>

Bob S. wrote:

> 

Bob,

If you do get the AJAX one done, do consider sharing 🙂

Cheers,  
Mohit.  
8/26/2007 | 5:03 PM.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 24, 2007, 10:12pm UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/5 "2007-08-24T22:12:27Z")

</div>

Philip and Mohit,

Thank you for the replies! I’m going to try all of your various ideas  
and see which works best. The AJAX one sounds really cool, and I think  
would be very use-friendly if done right.

Of course, relying on my skills isn’t the best, so we’ll see what  
happens 🙂

Thanks again!

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 27, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/6 "2007-08-27T16:48:45Z")

</div>

On 8/26/07, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Thanks again!
> 
> Bob,
> 
> If you do get the AJAX one done, do consider sharing 🙂

I do this in quite a few different places in my app… In one  
instance, an Event belongs\_to a venue, so I give the user the option  
to select any venue from a list, or they can create a new one by  
clicking on the “Create new venue…” option in the dropdown (I use a  
javascript onclick handler to detect when they select the appropriate  
option). I then display a hidden div which contains a form for  
creating a new venue.

An event can also be associated with an artist, so I use an ajax  
autocomplete field to display a list of artists. I then use something  
like @event.artist =  
Artist.find\_or\_initialize\_by\_artist\_name(params[:artist\_name]) which  
will either retrieve the Artist with the given name, or it’ll create a  
new instance, which will then be saved when I call @event.save.

So the Ajax code isn’t necessarily very complicated, it’s just a  
standard autocomplete field and uses find\_or\_initialize\_by\_\*.

Adam

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [August 29, 2007, 4:42am UTC](https://www.ruby-forum.com/t/choose-from-these-options-or-create-a-new-option/112909/7 "2007-08-29T04:42:15Z")

</div>

Adam C. wrote:

> > > Of course, relying on my skills isn’t the best, so we’ll see what
> 
> like @event.artist =  
> Artist.find\_or\_initialize\_by\_artist\_name(params[:artist\_name]) which  
> will either retrieve the Artist with the given name, or it’ll create a  
> new instance, which will then be saved when I call @event.save.
> 
> So the Ajax code isn’t necessarily very complicated, it’s just a  
> standard autocomplete field and uses find\_or\_initialize\_by\_\*.
> 
> Adam

Thanks Adam!

Cheers,  
Mohit.  
8/29/2007 | 10:41 AM.
