Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select onchange not being written

Rails 2.3.5, Ruby 1.86

I haven't been able to figure this out. The 'onchange' in the select below is not being written (no onchange written in the HTML). I haven't seen a reference to the syntax being different except in some older examples the onchange is surrounded in brackets:

<%= f.select :directory_id, options_for_select(@directories, @directory_to_select), :onchange => 'folder_lookup()' %>

results in:

<select id="contact_directory_id" name="contact[directory_id]">
<option value="2">test_1</option>
<option value="4">test_2</option>
<option value="33" selected="selected">test_3</option>
</select>


If I simply change "f.select" to "select_tag" the onchange is written correctly (not that I want to do that though):

<%= select_tag :directory_id, options_for_select(@directories, @directory_to_select), :onchange => 'folder_lookup()' %>

results in:

<select id="contact_directory_id" name="directory_id" onchange="folder_lookup()">
<option value="2">test_1</option>
<option value="4">test_2</option>
<option value="33" selected="selected">test_2</option>
</select>


Am I missing a syntax difference for onchange between a select and select_tag helper?

Thanks!

like image 563
Reno Avatar asked Feb 02 '11 15:02

Reno


1 Answers

This is what you want:

<%= f.select :directory_id, options_for_select(@directories, @directory_to_select), {}, :onchange => 'folder_lookup()' %>

With select the method signature looks like this select(object, method, choices, options = {}, html_options = {}). onchange is an html_option, since you don't have any options, you need an empty hash so that your last onchange is taken as an html_option.

like image 62
bobbywilson0 Avatar answered Sep 28 '22 13:09

bobbywilson0