I am trying to write my first RJS script to uncheck all radio buttons in
a div #network_radio_btns
page.select(''#network_radio_btns input'').each do |element|
element.set_attribute(''checked'', ''false'')
end
but this doesn''t work... being converted to js
$$("#network_radio_btns input").each(function(value, index) {
value.setAttribute("checked", "false");
});
I tested the loop : alert(index) and I can see all indexes but ...
how can I change an option ?.... not the value
thnaks for your help
kad
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi Kad, Kad Kerforn wrote:> I am trying to write my first RJS script to uncheck > all radio buttons in a div #network_radio_btns > > page.select(''#network_radio_btns input'').each do |element| > element.set_attribute(''checked'', ''false'') > end> I tested the loop : alert(index) and I can see all indexes but ... > how can I change an option ?.... not the valueI''d probably just render a new partial rather then trying to reset the button. If you really need to go this route, I think the visible properties of a radio button depend on the value being nil for unchecked. So you might need to add element.set_attribute(''value'', nil) I haven''t tested it though. hth, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Kad, > Kad Kerforn wrote: > >> I am trying to write my first RJS script to uncheck >> all radio buttons in a div #network_radio_btns >> >> page.select(''#network_radio_btns input'').each do |element| >> element.set_attribute(''checked'', ''false'') >> end > >> I tested the loop : alert(index) and I can see all indexes but ... >> how can I change an option ?.... not the value > > I''d probably just render a new partial rather then trying to reset the > button. If you really need to go this route, I think the visible > properties > of a radio button depend on the value being nil for unchecked. So you > might > need to add > > element.set_attribute(''value'', nil) > > I haven''t tested it though. > > hth, > Billthanks Bill You''re right... that''s what I going to do... it was a quizz for me trying to understand how to use JSCollectionProxy in RJS... (got teh PDF from Cody Fauser but.. there is no example... and I am not a JS guru... whatever I found also he solution using RJS : use plain JS... page.select(''#network_radio_btns input'').each do |index| page << "document.display_networkForm.network_group[index].checked = false" end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
maybe i''m missing something, but why would you need to do this using
rjs? from your example, you''re making a call to the server, which is
returning javascript to uncheck all the checkboxes in a div. why not
just use straight javascript and skip the server altogether?
assuming all the checkboxes are in a form element, you can do
something like this (requires prototype):
<form id="my_form">
...
</form>
<%= link_to_function "CHECK ALL",
"check_all(''my_form'')" -%>
<%= link_to_function "UNCHECK ALL",
"uncheck_all(''my_form'')" -%>
<script type="text/javascript">
function check_all(form) {
Form.getInputs(form, ''checkbox'').each( function(cb) {
cb.checked = true;
});
}
function uncheck_all(form) {
Form.getInputs(form, ''checkbox'').each( function(cb) {
cb.checked = false;
});
}
</script>
On 2/15/07, Kad Kerforn
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> Bill Walton wrote:
> > Hi Kad,
> > Kad Kerforn wrote:
> >
> >> I am trying to write my first RJS script to uncheck
> >> all radio buttons in a div #network_radio_btns
> >>
> >> page.select(''#network_radio_btns input'').each do
|element|
> >> element.set_attribute(''checked'',
''false'')
> >> end
> >
> >> I tested the loop : alert(index) and I can see all indexes but
...
> >> how can I change an option ?.... not the value
> >
> > I''d probably just render a new partial rather then trying to
reset the
> > button. If you really need to go this route, I think the visible
> > properties
> > of a radio button depend on the value being nil for unchecked. So you
> > might
> > need to add
> >
> > element.set_attribute(''value'', nil)
> >
> > I haven''t tested it though.
> >
> > hth,
> > Bill
>
> thanks Bill
>
> You''re right... that''s what I going to do...
> it was a quizz for me trying to understand how to use JSCollectionProxy
> in RJS... (got teh PDF from Cody Fauser but.. there is no example... and
> I am not a JS guru...
>
> whatever I found also he solution using RJS : use plain JS...
> page.select(''#network_radio_btns input'').each do |index|
> page <<
"document.display_networkForm.network_group[index].checked > false"
> end
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---