Forum: Ruby on Rails RJS, scriptaculous, page.replace problem with input fields?

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.
8360c3a75305def8f1ac0346f7e3b047?d=identicon&s=25 Noah Daniels (Guest)
on 2006-04-22 17:08
I'm hoping someone can help...

I have an rjs template that invokes a couple of page.remove() calls that
work fine, and a page.replace() call that does not.

I've played with the javascript extensively from within Firefox's
FireBug module, and it seems to me that this is what is happening:

What I'm trying to replace is an element that's been generated by a
check_box_tag call. So basically it's an element like this:

<input id="thumb_check_237" name="thumb_check_237" type="checkbox"
checked="checked" value="1" />

and I'm trying to replace it with this:

<input id="thumb_check_237" name="thumb_check_237" type="checkbox"
value="1" />

to basically uncheck the checkbox. What seems to be happening is that
page.replace() does not work correctly on single tags (like <input />
and <br />) but works fine on 'outer' tags like <li> </li>.

Does anyone have any idea what's going on here, or why this is
happening, or a workaround?

many thanks!
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-04-22 22:35
Noah Daniels wrote:
> I'm hoping someone can help...
>
> I have an rjs template that invokes a couple of page.remove() calls that
> work fine, and a page.replace() call that does not.
>
> I've played with the javascript extensively from within Firefox's
> FireBug module, and it seems to me that this is what is happening:
>
> What I'm trying to replace is an element that's been generated by a
> check_box_tag call. So basically it's an element like this:
>
> <input id="thumb_check_237" name="thumb_check_237" type="checkbox"
> checked="checked" value="1" />
>
> and I'm trying to replace it with this:
>
> <input id="thumb_check_237" name="thumb_check_237" type="checkbox"
> value="1" />
>
> to basically uncheck the checkbox. What seems to be happening is that
> page.replace() does not work correctly on single tags (like <input />
> and <br />) but works fine on 'outer' tags like <li> </li>.
>
> Does anyone have any idea what's going on here, or why this is
> happening, or a workaround?
>
> many thanks!

You could change the state of the checkbox with javascript.  You dont
really need to replace single tags, and should instead just be changing
their attributes.

Try:

  page["thumb_check_#{check_box_id}"].checked = false

which should generate:

  $("thumb_check_237").checked = false;
This topic is locked and can not be replied to.