I’m struggling to figure out the following;
I have a django form field hidden in {{ field.field }}
. It renders out as
<input type="text" name="field-id" value="100" id="id_set-0-product" class="vForeignKeyRawIdAdminField">
I can tagret it using jQuery by its id but I need to add a list = "choicelist"
which corresponds with
<datalist id="choicelist" style="text-align: center">
</datalist>
which I populate using ajax requests. How do I add the list = "choicelist"
to it? I am basically looking for something like .addClass() but for a list.
Any help would be much appreciated!
3
Answers
You have to use the attr() method for this:
You have two options
Using ID (it will add list attribute for particular field)
Using Class (it will add list attribute for all available field with the same class)
Using Django, add the attribute to the widget: