#25193: MultiWidget is_hidden is True if subwidgets are dynamically added during
its render function
-------------------------------+--------------------
Reporter: meredithroman | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------
I have a custom MultiWidget that dynamically adds subwidgets during its
render function. I use this widget as part of a form builder that lets a
user generate a checklist or radio field with as many options as they
need. Because I don't know how many subwidgets the user will need, I am
unable to set the subwidgets during form initializaiton.
This is how I add subwidgets during the MultiWidget's render function:
{{{
def render(self, name, value, attrs=None):
if not isinstance(value, list):
value = self.decompress(value)
self.widgets = []
for option in value:
self.widgets.append(forms.TextInput())
return super(OptionsWidget, self).render(name, value, attrs)
}}}
This is the way that the MultiWidget is_hidden property is currently set:
{{{
@property
def is_hidden(self):
return all(w.is_hidden for w in self.widgets)
}}}
Because I do not have any subwidgets assigned to my widget at form
initilaization, and because all() returns True on an empty iterable,
is_hidden was set to True for my widget.
I'm currently using this overwritten version of is_hidden for the widget:
{{{
@property
def is_hidden(self):
return False if self.widgets == [] else all(w.is_hidden for w in
self.widgets)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25193>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.8bf65b54ff067e7940357c29848e86a4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.