#29205: MultiValueField ignores a required value of a sub field
--------------------------------+-------------------------------------
Reporter: Takayuki Hirai | Owner: itergator
Type: Bug | Status: assigned
Component: Forms | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+-------------------------------------
Changes (by itergator):
* owner: David Smith => itergator
Comment:
I am experiencing this issue with the 2.2.10 LTS release too:
{{{
class RowSelectorField(forms.fields.MultiValueField):
def __init__(self, *args, **kwargs):
choices = kwargs.pop('choice')
fields = [forms.fields.ChoiceField(),
forms.fields.IntegerField(required=False)]
super(RowSelectorField, self).__init__(require_all_fields=False,
fields=fields, *args, **kwargs)
self.widget = RowSelectorWidget(choices=choices)
def compress(self, values):
return values
}}}
all of the fields in HTML are set to required, even the integer field. I
have noticed if I change the super call to:
{{{
super(RowSelectorField, self).__init__(required=False,
require_all_fields=False, fields=fields, *args, **kwargs)
}}}
and in the MultiWidget I use:
{{{
class RowSelectorWidget(forms.widgets.MultiWidget):
def __init__(self, choices, attrs=None):
choices.append((len(choices), _('custom')))
widgets = [forms.RadioSelect(choices=choices, attrs={'required':
True}),
forms.NumberInput(attrs={'required': False})]
super(RowSelectorWidget, self).__init__(widgets, attrs)
}}}
I do get the correct expected behaviour.
--
Ticket URL: <https://code.djangoproject.com/ticket/29205#comment:14>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.59f3915051c1172f8182c6a3368e2222%40djangoproject.com.