I have next form:
class ExampleForm(forms.ModelForm):
class Meta:
model = ExampleModel
fields = ['field1', 'field2', 'field3']
widgets = {'field1': forms.Select(attrs={'onchange': 'onchangeJsFunction()'})}
So far i have been able to add onchange property to my select field that calls 'onchangeJsFunction()' every time 'field1' value is changed. My next goal is to add a function that is going to be executed every time form is loaded, and i am not sure how to do it. I have tried adding onload property to a input field this way:
...
widgets = {'field_2': forms.TextInput(attrs={'onload': 'onloadJsFunction();'})}
...
but it does not give any results so far.
How am i supposed to execute certain JS function every time my Django Form is loaded?
<body>tag?