How to set a JavaScript function as handler in the event onclick in a given field of a Django Form. Is this possible?
Any clue would be appreciated.
The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.
Django forms are an advanced set of HTML forms that can be created using python and support all features of HTML forms in a pythonic way.
What I do for that is :
class MyForm(forms.Form):
stuff = forms.ChoiceField(
[('a','A'),('b','B')],
widget = forms.Select(attrs = {
'onclick' : "alert('foo !');",
}
)
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