On Fri, Jun 3, 2011 at 12:50 PM, Jody McIntyre <[email protected]> wrote:
> We need to be able to disable choices in a <select>, which is done by
> setting the disabled attribute on the <option> tag, for example:
> <option value="bananas" disabled="disabled">Bananas</option>
>
> Currently we're doing this by subclassing the Select widget:
> http://djangosnippets.org/snippets/2453/
>
> It would be nice if the built in Select widget supported this. One way
> would be to replace the existing render_option method with what I've
> written, and I can prepare a patch if desired, but this approach changes the
> format of the "choices" data structure to something that won't be understood
> by other widgets. Perhaps these widgets should be improved too, but I don't
> want to do this unless my changes have a good chance of being accepted.
>
> I logged this as a ticket (16149) and was told to discuss it here. To
> address aagustin's comments:
>
> 1. Backwards compatibility is already addressed. If the widget is passed a
> regular "choices" field, the existing behavior is preserved.
Sadly, not true. Any code inspecting the choices is going to break,
because there is a lot of code expecting it can unpack the choices
out of 2-tuples.
This must be preserved. Perhaps a Choice type could exist, a lot like
url() in our urls.py files, where we can use a tuple or a special type
to additional parameters.
choices = (('apples', 'Apples'),
('oranges', 'Oranges'),
Choice('bananas', 'Bananas', disabled=True),
('grobblefruit', 'Grobblefruit'))
> 2. I don't understand what you mean by "boilerplate" in the API. A
> "choices" field with a disabled choice looks like:
>
> choices = (('apples', 'Apples'),
> ('oranges', 'Oranges'),
> ('bananas', {'label': 'Bananas',
> 'disabled': True}),
> ('grobblefruit', 'Grobblefruit'))
>
> I can't think of a more concise way of clearly representing that 'bananas'
> is disabled while still allowing it to have a label, unless we want to
> change the "choices" data structure a lot more to something like:
>
> choices = (('apples', 'Apples'),
> ('oranges', 'Oranges'),
> ('bananas', 'Bananas', {'disabled': True}),
> ('grobblefruit', 'Grobblefruit'))
>
> Suggestions & other thoughts welcome :)
> Jody
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-developers?hl=en.
>
--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.