Is there any way to have observe_field react to the current value of a field also?

I have a view, seen below, that shows a list of churches if the zip
code isn't 01540 or 01537. This part works perfectly. The problem is
that this is the page is to edit an existing record also, so
observe_field needs to see that the zip code currently doesn't match,
so the church list needs to be shown. Currently, even if the zip
doesn't match, the list will only be shown after the field is changed,
even is the field is changed to the same value.. Here is the view,
controller code and church_select view in that order.. Please give me
a direction to look..

Thanks

Bob <bsm2th@gmail.com>

View
<STYLE TYPE="text/css">
<!--
big{font-family: Arial; font-size: 16pt;}
--->
</STYLE>
<% fields_for @household, :builder => TaggedBuilder do |
household_form| %>
<pre>
<div id="household">
<%= household_form.text_field :first_name, :maxlength => 50, :size =>
15, :autocomplete => "off", :class => 'household ' %>
<%= household_form.text_field :middle, :size => 1, :maxlength
=>1, :autocomplete => "off", :class => 'household ' %>
<%= household_form.text_field :last_name, :maxlength => 50, :size =>
20, :autocomplete => "off", :class => 'household ' %>
<%= household_form.text_field :address, :autocomplete => "off", :class
=> 'household ' %>
<%= household_form.text_field :zip, :size=> 5, :autocomplete =>
"off", :class => 'household ' %>
<%= household_form.text_field number_to_phone(:phone, :area_code =>
true), :autocomplete => "off", :size => 14, :class => 'household ' %>
</div>
<%= observe_field :household_zip,
          :url => {:controller => 'households', :action => 'watch_church'},
          :update => :church,
          :with => ':zip',
          :frequency=> 0.5 %>
<div id="church">
</div>
<u><b>Federal Programs</b></u> <b>Primary Income </b><%=
household_form.select(:primary, [['1. Employment', 1],['2.
Unemployment', 2],['3. SSI', 4],['4. TANF/EADC', 8],['5. Other', 16],
['6. None', 32]], :class => "household ") %>
<table> <tr><td><%= household_form.check_box :food_stamps %></

</tr>

                <tr><td><%= household_form.check_box :wic %></td></tr>
                <tr><td><%= household_form.check_box :school_breakfast %></

</tr>

                <tr><td><%= household_form.check_box :school_lunch %></td></

                <tr><td><%= household_form.check_box :SFSD %></td></tr></

</b></pre>
<% end %>

controller
  def watch_church
    # debugger
      if (params[':zip'] != "01540") && (params[':zip'] != "01537")
then
      render :partial => "church_select"
    else
      render(:nothing=>true)
    end
  end

church_select view
<b>Member of Local Church: </b> <%= collection_select('household',
'church_id', Church.find(:all), 'id', 'name') %>

HI Bob,

The problem is
that this is the page is to edit an existing record also, so
observe_field needs to see that the zip code currently doesn't match,
so the church list needs to be shown. Currently, even if the zip
doesn't match, the list will only be shown after the field is changed,

For the initial page load you just need to test and render if
appropriate on the initial page load.

<div id="church">
  <% if @household.zip != xxxxx and @household.zip != yyyyy %>
      <%= render :partial => "church_select %>
  <% end %>
</div>

You need to change the render :nothing in your controller to render an
empty string or partial to empty the content of the church div when
appropriate.

HTH,
Bill

How would this work with the observe_field later in the page ? This is
an edit page, so if the field is changed, the page needs to react
correctly This works fine for a new user, but will it be OK for changing
an existing user ?

Thanks for the reply

Bob

Hi Bob,

How would this work with the observe_field later in the page ? This is
an edit page, so if the field is changed, the page needs to react
correctly This works fine for a new user, but will it be OK for changing
an existing user ?

That's what the second part, below, is about.

You need to change the render :nothing in your controller to render an
empty string or partial to empty the content of the church div when
appropriate.

Best regards,
Bill

Never mind. I just tried it and it works perfectly. Thanks for the help.

Bob

Bob Smith wrote: