Forum: Ruby on Rails rails combo box

Posted by Mike Kogan (thekog)
on 2006-09-19 01:09
I need an editable combo box for a rails app where I can select from a 
list of values from the DB or have the user input a new one. Doing a 
plain old list box with options from the DB is easy. Can someone please 
direct me to info on the best way to do this? Will I need to resort to 
JavaScript to get it done?
Thanks in advance.
Posted by George S. Williams (Guest)
on 2006-09-19 02:31
(Received via mailing list)
On Mon, 2006-09-18 at 19:09, Mike Kogan wrote:
> I need an editable combo box for a rails app where I can select from a 
> list of values from the DB or have the user input a new one. Doing a 
> plain old list box with options from the DB is easy. Can someone please 
> direct me to info on the best way to do this? Will I need to resort to 
> JavaScript to get it done?
> Thanks in advance.

I don't think there's a way to do it without Javascript.

I've used the one at
http://www.xaprb.com/blog/2005/09/29/javascript-combo-box/

And then used this in the form-
<td><label for="invoice_project_name">Project name</label><br/>
<%= @projects=Invoice.find_by_sql(["select distinct project_name from
invoices where client = ? order by
project_name",@invoice['client']]).map {|u| [u.project_name,
u.project_name]}
@projects=@projects.unshift(@invoice['project_name'])
select(:invoice, :project_name, @projects, { },
{:onkeypress=>"edit(event);", :onblur=>"this.editing=false;"})%></td>


--
                         Sterling Web Services
                       http://www.websterling.com
                           The Web Done Right
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.