I have this ChoiceField in a Django form:
forms.py
sales_documents_description_1 = forms.ChoiceField(required=False, choices=list(models_products.objects.values_list( 'id_product','product_denomination')), widget=forms.Select(attrs={'id': 'sales_documents_editable_select_description_1','style': 'width:200px','onchange': 'populate_selected_product(this.id,this.value)'}))
In my template, how do I set the value of this ChoiceField by specifying the text argument (NOT THE VALUE).
I tried with this :
Template.html
# The ChoiceField is rendered like this :
{{ form5.sales_documents_description_1 }}
$('#sales_documents_description_1').filter(function() {return $(this).text() == 'Neumann U87';}).prop('selected', true);
or
$("#sales_documents_description_1 option").filter(function(){return $(this).text() == 'Neumann U87';}).prop('selected', true);
But it’s not working.
Any JS or jQuery solution will be ok for me.
9