Multiwidget internal widgets ID overridden bug?

21 views
Skip to first unread message

Sai Prasanna

unread,
Mar 2, 2014, 9:29:26 AM3/2/14
to django...@googlegroups.com

I saw that the render method in django.form.widgets. multiwidget class changes the id of internal widgets .Shouldn't it set internal widget ids if they are specified in attrs of widgets passed to the init.

Russell Keith-Magee

unread,
Mar 2, 2014, 7:19:02 PM3/2/14
to Django Users
On Sun, Mar 2, 2014 at 10:29 PM, Sai Prasanna <sai.r.p...@gmail.com> wrote:

I saw that the render method in django.form.widgets. multiwidget class changes the id of internal widgets .Shouldn't it set internal widget ids if they are specified in attrs of widgets passed to the init.

Hi Sai,

If I'm understanding you correctly, maybe :-)

I can certainly understand your position that if you're manually specifying an ID for a widget, then Django should use it in preference to generating it's own. From a quick inspection, normal "single" widgets certainly take this approach.

The behaviour you're seeing in MultiWidget looks like it's an artefact of making it easy to identify the individual subwidgets. If you pass in an id at the Field level, or as an ID attribute of the *multiwidget*, it will be preserved, and the sub widgets will get _0, _1… prefixes as appropriate. 

I can see your point that if you're manually specifying the widget IDs for the subwidgets, they should be preserved. 

If you worked up a full patch for this (with tests, and probably some clarifying documentation), I imagine it would probably be committed. 

My bigger question to you would be why you are specifying IDs at the widget level in the first place. To me, this is a flag that you're possibly being a little *too* specific in your code. If you're hard-coding (and requiring) a specific ID, it means your code is really only going to be useful in one particular place and time. 

You may well have a good reason for needing a specific ID for subwidgets, and if you do, that's fine. However, if you're just fixing IDs because you think you have to, I'd suggest taking a closer look at ways of making your code more reusable (e.g., by using class specifiers instead of IDs).

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages