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 this choicefield value by specifiying the text argument (NOT THE VALUE)
I tried with this :
Template.html
$('#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.
Thanks