0👍
✅
Finally, I found a solution! As catavaran said, that was not a Django dev server issue. I just misunderstood, how to correctly use ‘render’ and ‘value’ methods. In my case solution was simple:
$('.selectpicker').val('{{ request.user.profile.bd_month }}');
$('.selectpicker').selectpicker('render');
Thanks catavaran for help!
1👍
You should set selected
attribute to the selected <option>
instead of empty one:
<select id="id_bd_month" name="bd_month" class="selectpicker" ...>
<option value="01">January</option>
<option value="02" selected="selected">February</option>
Or as alternative pass the selected value to the selectpicker()
method:
$('.selectpicker').selectpicker('render');
$('.selectpicker').selectpicker('val', '{{ request.user.profile.bd_month}}');
- [Answer]-Django flatten dictionaries in ajax get / post
- [Answer]-Django raise forms.ValiadationError not displaying
- [Answer]-Django for loop list with jquery and javascript
Source:stackexchange.com