# Rendering partials with ajax checkbox/observer

**URL:** <https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617>\
**Category:** Rails\
**Created:** [July 6, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617 "2009-07-06T17:56:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 6, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617/1 "2009-07-06T17:56:51Z")

</div>

I decided to create an advanced search form which is stored in a partial  
called:

\_search.html.erb

Right now the partial just contains a simple two box nested form\_tag…

In my index.html I have the following:

\<% form\_tag controller.controller\_path, :method =\> ‘get’ do %\>  
Advanced Search  
\<%= check\_box “search”, “info” %\>  
\<%= observe\_field(:search\_info,  
:on=\>‘click’,  
:frequency=\>0.25,  
:update =\> :submit\_div,  
:with =\> :search\_info,  
:url =\> { :action =\> :search\_form }) %\>

\<% end -%\>

Which basically monitors the search\_info from the check\_box and when it  
hits an event onClick it goes to the search\_form method specified in my  
controller, updating :search\_info…

So, in my controller I tested all of the returns:

def search\_form  
validate\_date\_form  
if params[:search\_info] == “null”  
#render :text =\> “”  
render :text =\> "Debug search\_info unchecked = " +  
params[:search\_info]  
else  
#render :partial =\> “search”  
render :text =\> "Debug search\_info checked = " +  
params[:search\_info]  
end  
end

When I fire up my page, if I click the checkbox I receive:

Debug search\_info checked = “1”

If I uncheck the checkbox I receive:

Debug search\_info unchecked = “null”

If I comment out the debug lines and uncomment what’s listed above the  
following occurs:

Firefox:

If I check the box the partial is rendered. If I uncheck the box, the  
partial is removed.

Internet Explorer:

If I check the box, nothing happens. If I uncheck the box, I can see a  
slight buffer from the empty div showing so the “null” is accepted.

Why is the partial not rendering in I.E.?

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 6, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617/2 "2009-07-06T18:19:14Z")

</div>

Update:

Firefox 3.5 =\> partial renders OK  
Opera 9.6.4 =\> partial renders OK  
Safari 4.0 =\> partial renders OK

Internet Explorer 8 =\> partial does not render

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 6, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617/3 "2009-07-06T18:19:06Z")

</div>

On Jul 6, 4:56 pm, “Älphä Blüë” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> If I check the box, nothing happens. If I uncheck the box, I can see a  
> slight buffer from the empty div showing so the “null” is accepted.
> 
> Why is the partial not rendering in I.E.?

Looks like your html will be invalid (so browsers can do what they  
want), as when your partial is rendered you’ll end up with a form  
nested inside a form (at least that’s my reading of your code)

Fred

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 6, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617/4 "2009-07-06T18:24:53Z")

</div>

Sorry Fred,

I’m dense this morning - I figured it out:

```
  <td align="left" valign="middle">
    Advanced Search
    <%= check_box "search", "info" %>
    <%= observe_field(:search_info,
      :on=>'click',
      :frequency=>0.25,
      :update => :submit_div,
      :with => :search_info,
      :url => { :action => :search_form }) %>
    <div id="submit_div">
    </div>
  </td>

```

I forgot that I was going with an older model where I’d verify a submit.  
I didn’t need the first form at all. I forgot to remove that…

Thanks!

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 6, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/rendering-partials-with-ajax-checkbox-observer/171617/5 "2009-07-06T18:21:26Z")

</div>

Frederick C. wrote:

> On Jul 6, 4:56ï¿½pm, “ï¿½lphï¿½ Blï¿½ï¿½” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > If I check the box, nothing happens. ï¿½If I uncheck the box, I can see a  
> > slight buffer from the empty div showing so the “null” is accepted.
> > 
> > Why is the partial not rendering in I.E.?
> 
> Looks like your html will be invalid (so browsers can do what they  
> want), as when your partial is rendered you’ll end up with a form  
> nested inside a form (at least that’s my reading of your code)
> 
> Fred

Sorry Fred,

Didn’t see your message before I last posted…

What do you suggest I do regarding what I’m trying to accomplish?

I just want a checkbox that when checked displays my search form and  
when unchecked displays an empty rendered text.

Should I place the rendered form in another area that makes it unnested?
