Thursday, February 28, 2019

"onchange" event with "autocomplete_fields"


 Into my admin site I have some Selects (from foreignKeys) for which I'm able to add a "change" event so that when I choose an option from the Select's dropdown somethings happens to the other fields via an AJAX request. I'm doing this using djquery, directly into the <script> section of my template.html with something such as $("#id_selector").on('change', myFunction() {......}

Now I wanted to do the same using an "Autocomplete_field" widget but I'm not able to add any "on" event via jquery, it seems they are ignored even if they appear into the HTML source page. But if I add this "onchange"  as an attribute of the field's widget (e.g.  form.base_fields['myField'].widget.attrib['onchange']='myUpdateFieldsFunction()'  )  then it works.

Is this intended? 



No comments:

Post a Comment