Multiple Select, Mark selected items on page load


Topic: Multiple Select, Mark selected items on page load

Ronald Patino asked 8 years ago

Hi I am currently integrating MDB with Grails 3 My question is how to mark all the selected items in a multiple select when the page loads. Of course I already have the selected items which are passed to the page. Hope you can shed some light. Thanks
Sorry I forgot to mention I am using MDB4 pro
Hi, I have a solution for you. It's quite ugly but it should work for now. HTML:

<select class="mdb-select" multiple>
    <option value="" disabled selected>Choose your option</option>
    <option value="1" class="active selected">Option 1</option>
    <option value="2" class="active selected">Option 2</option>
    <option value="3" class="active selected">Option 3</option>
</select>
<label>Example label</label>
JS:

$(document).ready(function() {

	$('.mdb-select').material_select();

	var x = $('.dropdown-content').find('li');

	for(let i = 1; i <= 4; i++) {
		x.eq(i).trigger('click');
	}

	$('body').trigger('click');

});

Hi Adrian thanks for your reply. I will give a try. Cheers
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
  • User: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No