0

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 %>
Jay
  • 6,206
  • 11
  • 48
  • 82

3 Answers3

2

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.

hurikhan77
  • 5,881
  • 3
  • 32
  • 47
1

The id of the field is usually something like id='group_item_id', could this be the issue?

Mark Swardstrom
  • 17,217
  • 6
  • 62
  • 70
  • thank you Swards and hurikhan77. the onchange event is now observed so one step closer! i updated the snippet above for your input. now i am getting a syntax error on... – Jay Nov 09 '10 at 20:35
  • :with => "'group_item_id=' + escape(value)" – Jay Nov 09 '10 at 20:35
  • changing to... :with => "'item_id=' + escape(value)" also results in... syntax error, unexpected '.', expecting ')' :with => "'item_id=' + escape(value)" ).to_s); @output_buffer.concat "\n" – Jay Nov 09 '10 at 20:42
  • @Jay Use `:with => :group_item_id` - no fancy escaping or similar. Rails will do the magic for you. If you really want to use the escape function, use `escape(this.value)`. – hurikhan77 Nov 09 '10 at 21:01
  • there was an extra character that i took out so the syntax is fixed... but still not saving the data. – Jay Nov 09 '10 at 21:44
0

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

Jay
  • 6,206
  • 11
  • 48
  • 82