Answer the question
In order to leave comments, you need to log in
Why doesn't the required=True attribute work on the ChoiceField form field?
Hello!
The problem is this:
When trying to submit form data with an unselected radiobutton, it does not give a message about the impossibility of such an action, such as with an empty Charfield field. It is possible to determine that nothing is selected only when validating the form in the view. How can I fix this or is it a standard widget that does not provide for such work?
The code :
class HorizontalRadioRenderer(forms.RadioSelect.renderer):
def render(self):
return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))
class PaySendForm (forms.Form):
pay_system_choices = (
('OSP', ''),
('QIW', ''),
('P2P', ''),
('TST', ''),
)
pay_method = forms.ChoiceField(widget=forms.RadioSelect(renderer=HorizontalRadioRenderer),
choices=pay_system_choices, label='', required=True)
sum = forms.IntegerField(label='', min_value=100, max_value=100000, required=True)
Answer the question
In order to leave comments, you need to log in
Try to add the widget
directly to the html, it will become mandatory
Well, or check from_valid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question