Bob Smith
2010-Jun-28 20:16 UTC
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 %></ td></tr> <tr><td><%= household_form.check_box :wic %></td></tr> <tr><td><%= household_form.check_box :school_breakfast %></ td></tr> <tr><td><%= household_form.check_box :school_lunch %></td></ tr> <tr><td><%= household_form.check_box :SFSD %></td></tr></ table> </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'') %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bill Walton
2010-Jun-29 11:52 UTC
Re: Is there any way to have observe_field react to the current value of a field also?
HI Bob, On Mon, Jun 28, 2010 at 3:16 PM, Bob Smith <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bob Smith
2010-Jun-29 17:28 UTC
Re: Is there any way to have observe_field react to the current value of a field also?
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> <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-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bill Walton
2010-Jun-29 17:40 UTC
Re: Re: Is there any way to have observe_field react to the current value of a field also?
Hi Bob, On Tue, Jun 29, 2010 at 12:28 PM, Bob Smith <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bob Smith
2010-Jun-29 17:54 UTC
Re: Is there any way to have observe_field react to the current value of a field also?
Never mind. I just tried it and it works perfectly. Thanks for the help. Bob Bob Smith wrote:> 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 > >> <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-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.