Topic: How to add/remove select option dynamically with mdb3 pro?

wunailiang pro asked 7 years ago


This is my code with some django template langage:
<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 display bug. After check in firefox's inspector, I found added some <span class="caret">▼</span>code. How to fix it? Thanks very much!

wunailiang pro answered 7 years ago


I have found a solution add $('div.input-field').children('span.caret').remove(); after $('select').material_select();

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No
Tags