Topic: How to add/remove select option dynamically with mdb3 pro?
wunailiang
pro
asked 6 years ago
This is my code with some django template langage:
. After check in firefox's inspector, I found added some
<script>
function get_final_user(){
var selectedClass = $( '#id_finalUserClass').val();
console.log(selectedClass);
{% for classItem in classItems %}
{% for item in classItem.finaluser_set.all %}
$("#id_finalUserName option[value='{{item.userName}}']").remove();
if(selectedClass == "{{item.userClass}}")
{
$("#id_finalUserName").append("<option value='{{item.userName}}'>{{item.userName}}</option>");
}
{% endfor %}
{% endfor %}
if(selectedClass=="")
{
{% for classItem in classItems %}
{% for item in classItem.finaluser_set.all %}
$("#id_finalUserName option[value='{{item.userName}}']").remove();
$("#id_finalUserName").append("<option value='{{item.userName}}'>{{item.userName}}</option>");
{% endfor %}
{% endfor %}
}
$(document).ready(function () {
$('select').material_select();
});
};
</script>
I want change the options dynamically, after add the code ' $('select').material_select(); ' it works.
But there are some display bugs like <span class="caret">▼</span>
code.
How to fix it?
Thanks very much!
Add comment
wunailiang
pro
answered 6 years ago
I have found a solution
add
$('div.input-field').children('span.caret').remove();
after $('select').material_select();
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Status
Specification of the issue
- User: Pro
- Premium support: No
- Technology: General Bootstrap questions
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: Yes
- Provided link: No
Tags