Reputation: 6244
i have used observed_field for arrays of data... but i am having trouble making a simple, one field application of it work. i must be missing a very simple detail. have searched extensively for basic syntax and cannot find anything that applies. when i change the selection, the change is not saved and there is no error msg.
<% form_for :team, :url => update_item_leader_group_path do |f| %>
<%= f.select :item_id, @selection_collection %>
<span id="trigger_spinner" style="visibility: hidden;">
<img src="/images/spinner.gif" alt="Loading..." />
</span>
<%= observe_field 'group_item_id',
:url => { :controller => :group, :action => :update_item },
:method => :put,
:with => "'trig=' + $('group_item_id').value" %>
:loading => "$('trigger_spinner').setStyle({visibility: 'visible'});",
:complete => "$('trigger_spinner').setStyle({visibility: 'hidden'});" %>
<% end %>
Upvotes: 0
Views: 837
Reputation: 6244
corrected syntax above 1. form path 2. observer "url" 3. observer "with"
there was also a routing problem. i had to move update_item from a map.resources member to collection
Upvotes: 0
Reputation: 5930
The onchange
event may not be observed until you leave the focus of the select field. To watch some field changes instantly your only option is to use a form observer.
BTW: The dom id
of your field is probably not item_id
due to usage of the form builder. @Swards already pointed that out.
Upvotes: 2
Reputation: 18080
The id of the field is usually something like id='group_item_id', could this be the issue?
Upvotes: 1