Forum: Ruby on Rails checkbox connundrum

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
39025a7f572d6fe464e1fe6be399ca3b?d=identicon&s=25 Mike Dershowitz (mdersh53)
on 2007-02-07 14:54
Hi:

I have a bit of a checkbox connundrum I need some help with.

I have a page that displays a list of tasks.  These tasks have a bunch
of information on

them.  I want to do a fairly normal operation with a checkbox.  the
checkbox indicates when

the task is complete.  The checkbox needs to do the following things:

1. call a method that will make various database updates
2. change it's own label from "Complete?" to "Completed"
3. Change the text of the task from normal to strikethrough

It looks like I need to use form_remote_tag and make an AJAX call so all
of this can be

handled in real-time.  But he example from Cody Fauser's book don't seem
to translate for

me.  This is how far I've gotten:

FROM THE VIEW:
    <%= form_remote_tag :url => { :action => 'OTcomplete' }, :html => {
:id =>

'OTcomplete' } %>
      <%= check_box_tag ("OTcomplete", nil, checked = false, options = {
}

) %>
      <div id="OTcomplete"><span class="label">Completed?</span></div>
    <%= end_form_tag %>


FROM THE RJS "OTcomplete"

page.insert_html :bottom, 'OTcomplete', :partial => 'OTComplete'
page.visual_effect :highlight, 'OTcomplete'

FROM THE PARTIAL "_OTComplete"

<span class="label"><b>Complete</b></span>

FROM THE MODEL

The model has some code in it to make a DB insert when the user clicks
the checkbox

Here's what I didn't do yet:

1. implement the strikethrough of the text name
2. figure out how to reverse this process if the user clicks a checkbox
that has been

changed to "Complete"

Thank you very much in advance for your help!

Mike
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-02-07 15:34
(Received via mailing list)
Mike Dershowitz wrote:
>
> I have a bit of a checkbox connundrum I
> need some help with.

I can see a couple of things that are going to be problems.  But I can't
tell from your description exactly what problem you're having right now.
What is your code doing / not doing that you need help with?

> I have a page that displays a list of tasks.  These
> tasks have a bunch of information on them.

> FROM THE VIEW:
>    <%= form_remote_tag :url => { :action => 'OTcomplete' },
: :html => {:id => 'OTcomplete' } %>
>      <%= check_box_tag ("OTcomplete", nil, checked = false,
> options = { } ) %>
>      <div id="OTcomplete"><span class="label">Completed?</span></div>
>    <%= end_form_tag %>

You've given both the form and the div within it the same id.  That's
bad.
Each DOM element needs to have a unique id.  Ajax depends on it to find
the
element to update.  If I understand what you've said, you're generating
a
form element for each item.  If that's right, then the problem is
compounding .

First step is to take the rendered page source and validate it at
http://validator.w3.org/ .  If the xhtml doesn't validate without errors
(warnings are ok), then you're going to have problems.

Best regards,
Bill
This topic is locked and can not be replied to.