Hello I am trying to submit a form when selection an option on a ChoiceField
class ActionForm(forms.Form):
""" Holds the options for mailbox management """
choices = ['create new folder', 'delete', 'read', 'unread']
action = forms.ChoiceField(choices=choices, attrs={'onchange': 'actionform.submit();'})
but now I get an invallid syntax when I try to load the form. I am pretty sure the attrs={'onchange': 'actionform.submit();'})
is the problem, but not sure how else to do it.
You need to set a widget
argument on the field and pass attrs
argument:
action = forms.ChoiceField(choices=choices,
widget=forms.Select(attrs={'onchange': 'actionform.submit();'}))
Also, the choices
list should contain items containing two things inside:
choices = [(0, 'create new folder'), (1, 'delete'), (2, 'read'), (3, 'unread')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With