I''m turning my head around and around on this topic and not many searches on the web turn up what I need to do. Here''s the simple issue: I have an ajax search form that is activated via checkbox/observer: <%= check_box "search", "info" %> <%= observe_field(:search_info, :on=>''click'', :frequency=>0.25, :update => :form_container, :with => :search_info, :url => { :action => :search_form }) %> <div id="form_container"></div> If they check the box, the search_form action renders the search form: def search_form validate_date_form if params[:search_info] == "null" render :text => "" else render :partial => "search" end end All I want to do is degrade to a normal render if the user has scripting disabled. So, if scripting is disabled, the search form should be rendered always. If not, then only rendered on checkbox. How can I do this? I''m using prototype/scriptaculous so I thought it might have to do with providing a check with if request.xhr? is true or not... Any help would be appreciated. -- Posted via http://www.ruby-forum.com/.
bill walton
2009-Aug-02 23:36 UTC
Re: Checking whether or not scripting is enabled or disabled
Hi Joel, On Mon, 2009-08-03 at 01:04 +0200, Alpha Blue wrote:> All I want to do is degrade to a normal render if the user has scripting > disabled. So, if scripting is disabled, the search form should be > rendered always. If not, then only rendered on checkbox. > > How can I do this?This is what render |format| is about. HTH, Bill
Alpha Blue
2009-Aug-03 01:12 UTC
Re: Checking whether or not scripting is enabled or disabled
There''s a dozen topics on render .. something, none of which talks about the issue I''m having. Anyone else want to explain how I can accomplish this that can provide more than 7 words? Many thanks in advance. -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Aug-03 01:19 UTC
Re: Checking whether or not scripting is enabled or disabled
On Aug 3, 2:12 am, Alpha Blue <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> There''s a dozen topics on render .. something, none of which talks about > the issue I''m having. Anyone else want to explain how I can accomplish > this that can provide more than 7 words? >Instead of loading the form via an ajax request, make it part of the initial page. When the page loads, executes some javascript that hides the search form. If javascript is disabled then that code doesn''t run and so the form isn''t visible, if it is enabled then it will be hidden. Fred> Many thanks in advance. > > -- > Posted viahttp://www.ruby-forum.com/.
Alpha Blue
2009-Aug-03 01:45 UTC
Re: Checking whether or not scripting is enabled or disabled
Hi Fred, Thanks mate. I hadn''t thought of a backwards compatible type of an approach. I''ll see what I can do. Take care. -- Posted via http://www.ruby-forum.com/.
Alpha Blue
2009-Aug-03 03:00 UTC
Re: Checking whether or not scripting is enabled or disabled
Fred, thanks for the help. I was able to do: <%= check_box "search", "info" %> <%= observe_field(:search_info, :on=>''click'', :frequency=>0.25, :update => :form_container, :with => :search_info, :url => { :action => :search_form }) %> <% controller.response.content_type = Mime::HTML%> <div id="hide_container"><%= render :partial => ''search'' %></div> <div id="form_container"></div> <%= javascript_tag render( :partial => ''hide_div.js.rjs'') %> And then in the rjs partial I placed: page.hide :hide_container This allowed the search partial to be displayed in the div id for hide_container which is viewable by those without ajax/scripting enabled. And the render for rjs hides that partial and the checkbox/observer still allows the form to be viewed click/unclick. It looks fairly clean. -- Posted via http://www.ruby-forum.com/.
Alpha Blue
2009-Aug-03 03:19 UTC
Re: Checking whether or not scripting is enabled or disabled
For clarity in case someone else finds this topic, the final fixes were: _hide_div.js.rjs page.hide :hide_container page.show :show_checkbox index.html.erb <div id="show_checkbox" style="display:none;">Advanced Search <%= check_box "search", "info" %></div><br> <%= observe_field(:search_info, :on=>''click'', :frequency=>0.25, :update => :form_container, :with => :search_info, :url => { :action => :search_form }) %> <div id="hide_container"><%= render :partial => ''search'' %></div> <div id="form_container"></div> <%= javascript_tag render( :partial => ''hide_div.js.rjs'') %> <% controller.response.content_type = Mime::HTML%> This automatically hides the "Advanced Search []" and checkbox for those with javascript disabled. These are re-enabled by page.show :show_checkbox which applies to the div id="show_checkbox. The page.hide :hide_container then hides the div for div id="hide_container" from view for people that use ajax. -- Posted via http://www.ruby-forum.com/.