Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an event handler in a Django form input field

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.

like image 588
Alex. S. Avatar asked Nov 07 '09 21:11

Alex. S.


People also ask

What is form Is_valid () in Django?

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.

What is form AS_P in Django?

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.


1 Answers

What I do for that is :

class MyForm(forms.Form):
    stuff = forms.ChoiceField(
        [('a','A'),('b','B')],
        widget = forms.Select(attrs = {
            'onclick' : "alert('foo !');",
            }
        )
like image 57
Ghislain Leveque Avatar answered Sep 22 '22 13:09

Ghislain Leveque