I’m trying to use a form.select with a a simple javascript alert.
This is my code.
<%= form.select(:entry_type, Entry::TYPES, :prompt => “Select The
Type”, :onChange => “alert(‘test’)”) %>
The form loads without any issue, but onChange is not in the HTML
source. Of course, since the onChange is not in the source, nothing
happens regardless of the list item I select.
Does anybody know what is going on? Why is the onChange not appearing
in the source?
One of the major joys and challenges of Rails is how many different ways
it
supports to pass raw HTML attributes into methods that generate HTML.
It’s a
credit to Ruby’s infinite flexibility that Rails can support so many.
For example, the above method doesn’t take just one trailing hash. (A
trailing hash is how most :foo => :bar magic works, without {}). In this
case, Rails takes some fixed arguments, then takes two hashes, one for
dynamic options and the other for raw HTML arguments.
Research the prototype to your select, and determine which argmument
gets
the :onchange.