OmenKing
2007-Mar-21 23:06 UTC
[disabling fields] using prototype with select form helpers
I have a toggle for enabling and disabling a select field in my form.
This is how I want it to work.
[img]http://img260.imageshack.us/img260/8167/
disablefieldsassignedonrt6.gif[/img]
I can disable the select fields by selecting each one
application.js
[code=]function assigned_on_toggle()
{
if ( $(''assigned_on'').value == ''0'' )
{
$(''assigned_on_wrap'').className =
''assigned_on'';
$(''note_assigned_on_3i'').disabled = '''';
$(''assigned_on'').value = ''1'';
$(''assigned_on'').checked = ''checked'';
}
else
{
$(''assigned_on_wrap'').className = ''assigned_on
disable'';
$(''note_assigned_on_3i'').disabled =
''disabled'';
$(''assigned_on'').value = ''0'';
$(''assigned_on'').checked = '''';
}
}[/code]
This works however id have to $() every select field.
When I attempt to select all as such:
[code=]$(''assigned_on_wrap, ''select'').disabled =
''disabled '';[/code]
or
[code=]$$(''div.assigned_on_wrap select'').disabled =
''disabled '';[/
code]
It has no affect on to the fields, they just stay enabled.
Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Tom Gregory
2007-Mar-21 23:19 UTC
Re: [disabling fields] using prototype with select form helpers
$$ returns an array, which doesn''t have a disabled property (until
you add it). You''ll need to iterate through them, such as with each.
$$(''.someClass select'').each(function(el){el.disabled =
true;});
TAG
On Mar 21, 2007, at 5:06 PM, OmenKing wrote:
>
> I have a toggle for enabling and disabling a select field in my form.
>
> This is how I want it to work.
> [img]http://img260.imageshack.us/img260/8167/
> disablefieldsassignedonrt6.gif[/img]
>
> I can disable the select fields by selecting each one
> application.js
> [code=]function assigned_on_toggle()
> {
> if ( $(''assigned_on'').value == ''0'' )
> {
> $(''assigned_on_wrap'').className =
''assigned_on'';
> $(''note_assigned_on_3i'').disabled =
'''';
> $(''assigned_on'').value = ''1'';
> $(''assigned_on'').checked = ''checked'';
> }
> else
> {
> $(''assigned_on_wrap'').className = ''assigned_on
disable'';
> $(''note_assigned_on_3i'').disabled =
''disabled'';
> $(''assigned_on'').value = ''0'';
> $(''assigned_on'').checked = '''';
> }
> }[/code]
> This works however id have to $() every select field.
> When I attempt to select all as such:
>
> [code=]$(''assigned_on_wrap, ''select'').disabled =
''disabled '';[/code]
> or
> [code=]$$(''div.assigned_on_wrap select'').disabled =
''disabled '';[/
> code]
> It has no affect on to the fields, they just stay enabled.
> Any suggestions?
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
OmenKing
2007-Mar-22 00:35 UTC
Re: [disabling fields] using prototype with select form helpers
I made sure to add disabled to my select.
<%= date_select ''note'', ''assigned_on'', {
:order =>
[:day, :month, :year], :disabled => true } %>
This is generated html
<div id="assigned_on_wrap" class="assigned_on
disable">
<label for="note_assigned_on">Assigned On</label>
<input id="assigned_on" type="checkbox"
value="1"
onclick="assigned_on_toggle();" name="assigned_on"/>
<select id="note_assigned_on_3i" disabled="disabled"
name="note[assigned_on(3i)]"></select>
<select id="note_assigned_on_2i" disabled="disabled"
name="note[assigned_on(2i)]"></select>
<select id="note_assigned_on_1i" disabled="disabled"
name="note[assigned_on(1i)]"></select>
</div>
I made the changes as suggested.
function assigned_on_toggle()
{
if ( $(''assigned_on'').value == ''0'' )
{
$(''assigned_on_wrap'').className =
''assigned_on'';
$$(''div.assigned_on_wrap
select'').each(function(el){el.disabled false;});
$(''assigned_on'').value = ''1'';
$(''assigned_on'').checked = ''checked'';
}
else
{
$(''assigned_on_wrap'').className = ''assigned_on
disable'';
$$(''div.assigned_on_wrap
select'').each(function(el){el.disabled true;});
$(''assigned_on'').value = ''0'';
$(''assigned_on'').checked = '''';
}
}
I receive no errors from firebug, the fields just stay disabled now.
On Mar 21, 7:19 pm, Tom Gregory <t...-PGZyUNKar/Q@public.gmane.org>
wrote:> $$ returns an array, which doesn''t have a disabled property (until
> you add it). You''ll need to iterate through them, such as with
each.
>
> $$(''.someClass select'').each(function(el){el.disabled =
true;});
>
> TAG
>
> On Mar 21, 2007, at 5:06 PM, OmenKing wrote:
>
>
>
> > I have a toggle for enabling and disabling a select field in my form.
>
> > This is how I want it to work.
> > [img]http://img260.imageshack.us/img260/8167/
> > disablefieldsassignedonrt6.gif[/img]
>
> > I can disable the select fields by selecting each one
> > application.js
> > [code=]function assigned_on_toggle()
> > {
> > if ( $(''assigned_on'').value ==
''0'' )
> > {
> > $(''assigned_on_wrap'').className =
''assigned_on'';
> > $(''note_assigned_on_3i'').disabled =
'''';
> > $(''assigned_on'').value =
''1'';
> > $(''assigned_on'').checked =
''checked'';
> > }
> > else
> > {
> > $(''assigned_on_wrap'').className =
''assigned_on disable'';
> > $(''note_assigned_on_3i'').disabled =
''disabled'';
> > $(''assigned_on'').value =
''0'';
> > $(''assigned_on'').checked =
'''';
> > }
> > }[/code]
> > This works however id have to $() every select field.
> > When I attempt to select all as such:
>
> > [code=]$(''assigned_on_wrap,
''select'').disabled = ''disabled '';[/code]
> > or
> > [code=]$$(''div.assigned_on_wrap select'').disabled =
''disabled '';[/
> > code]
> > It has no affect on to the fields, they just stay enabled.
> > Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Mar-22 08:14 UTC
Re: [disabling fields] using prototype with select form helpers
Hey there, OmenKing a écrit :> $$(''div.assigned_on_wrap select'').each(function(el){el.disabled > $$(''div.assigned_on_wrap select'').each(function(el){el.disabledYour assigned_on_wrap is an ID, not a CLASS. Use this: $$(''#assigned_on_wrap select'').each(function(el) { el.disabled = ... }); -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---