开发者

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜