Checking whether or not scripting is enabled or disabled

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 }) %>

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.

Hi Joel,
On Mon, 2009-08-03 at 01:04 +0200, Alpha B. 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

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.

On Aug 3, 2:12 am, Alpha B. [email protected]
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

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.

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%>

<%= render :partial => ‘search’
%>


<%= 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.

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

Advanced Search <%= check_box "search", "info" %>

<%= observe_field(:search_info, :on=>'click', :frequency=>0.25, :update => :form_container, :with => :search_info, :url => { :action => :search_form }) %>
<%= render :partial => 'search' %>
<%= 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.