Topic: observe_field not working

I have two text boxes that need different values based on what the user selects in a drop down list.  The text boxes are located in _location_defaults.rhtml.

I have created a collection_select, and added the observe_field.  The problem seems to be that the method on the controller is not being called.  I have made sure that javascript is included.  This is the code I have:

# _location_defaults.rhtml

<p><label for="calendar_event_capacity">Capacity:</label>
<%= text_field 'calendar_event', 'capacity', :value => @capacity  %></p>
<p><label for="calendar_event_cost">Cost:</label>
<%= text_field 'calendar_event', 'cost', :value => @cost  %></p>

# Form

<p><label for="calendar_event_location">Restaurant:</label>
<%= collection_select( :calendar_event, :location_id, @venues, :id, :location_name ) %>

<div id="location_defaults">
  <%= render :partial => 'location_defaults' %>
</div>

<%= observe_field(
  :calendar_event_location_id,
  :frequency => 0.25,
  :update =>'location_defaults',
  :url => {:action => 'changeLocationDefaults' },
  :with => "'location=' + value" )
%>

# Controller
def changeLocationDefaults
  logger.error( "HERE I AM!!!!!!" )   # Added to see if this is getting called
  @capacity = 3598                    # Set a nonsense value to see if it updates
  @cost = 850.03                      # ditto
  render :partial => 'location_defaults', :layout => false  # Is this necessary?
end


What am I missing?

Thanks,

Steve

Re: observe_field not working

Try making the action lowercase:

<%= observe_field(
  :calendar_event_location_id,
  :frequency => 0.25,
  :update =>'location_defaults',
  :url => {:action => 'change_location_defaults' },
  :with => "'location=' + value" )
%>

# Controller
def change_location_defaults
  #...
end


Also, what happens when you call this action directly in the browser? Perhaps an exception is raised?

Railscasts - Free Ruby on Rails Screencasts

Re: observe_field not working

If I call the action directly from the browser, it renders the partial page, just like I would expect it to.

I played around some, and this is what I found.  Originally, I was calling the form in a popup window.  If I removed the :popup => true from the link_to, everything seems to work pretty well, (after I changed the action to lowercase).  When I try to popup the form, things don't work as well.  Nothing works until I manually refresh the page.  Then it starts to work intermittently.

Not popping up the form is a viable solution in this case, but I wonder is there some trick I'm missing to get it to work in popup mode?

Thanks,

Steve