Hi all,
Sorry to repeat a question that might be stupid, but I could really use
some help with this.
Does anybody know if there is a way to get observe_field to work with
hidden_field? I have a series of drop-down <select> menus that guide
the user through a narrowing series of options; each of these
drop-downs relies upon observe_field to generate the next one an option
is chosen. On some occasions, there may be only one option available,
in which case there should not be a <select> drop-down but the name of
the option is delivered inline, the value placed in a hidden form
element, and the next drop-down should be generated. But observe_field
doesn''t seem to work on a hidden field. Something like
periodically_call_remote would work, except that (1) if needs to take a
value to the controller, and (2) it should only happen once.
This is what the view is looking like at the moment; observe_field, as
noted, does not work with the results of the <else> branch.
<% if @departments.length > 1 %>
<%= select("article", "department_id",
@departments.collect {|d|
[d.department_name, d.id] }) %>
<% else %>
<%= h(@departments.first.department_name) %>
<%= hidden_field("article", "department_id") %>
<% end %>
<%= observe_field("article_department_id",
:frequency => 0.25,
:update => "article_type",
:url => { :action => "add_article_type" },
:with => "''department_id=''+value") %>
My sleep deprivation thanks anyone who can help,
Rob
Mark Reginald James
2005-Oct-26 15:22 UTC
Re: Simple AJAX/javascript helpers problem (I think)
Robert Wheaton wrote:> Does anybody know if there is a way to get observe_field to work with > hidden_field? I have a series of drop-down <select> menus that guide the > user through a narrowing series of options; each of these drop-downs > relies upon observe_field to generate the next one an option is chosen. > On some occasions, there may be only one option available, in which case > there should not be a <select> drop-down but the name of the option is > delivered inline, the value placed in a hidden form element, and the > next drop-down should be generated. But observe_field doesn''t seem to > work on a hidden field. Something like periodically_call_remote would > work, except that (1) if needs to take a value to the controller, and > (2) it should only happen once.If there is only one choice, return and render both the hidden field and the next select, with the observe_field acting only on the latter. -- We develop, watch us RoR, in numbers too big to ignore.