Material select selecting option


Topic: Material select selecting option

Jorge Nuñez Malledo asked 5 years ago

Hello,

I'm having trouble using jquery code to select material select options. Finally got some time to isolate the problem

Having the snipped below, I have three questions

1. Why the selected option is not displayed?

2. Why option[value="2"] is not selected after this simple code?

$('#selectValue2-button').click(function() {

$('#select4-select option:selected').prop('selected', false); // clear previously selected value

$('#select4-select option[value="2"]').prop('selected', true); // Select value = 2

console.log('Selected value: ' + $('#select4-select').val()); // Check that value 2 is actually selected

$('.mdb-select').materialSelect({ destroy: true });

$('.mdb-select').materialSelect({});

})

3. Why this is working properly in version 4.8.2?

Expected behavior

'Select...' option selected

'Option 2' selected after pressing of button

Actual behavior

No option selected before button click

No option selected after button click

Resources

https://mdbootstrap.com/snippets/jquery/jorge_nunez_malledo/1293486


Sebastian Kaczmarek staff pro premium commented 5 years ago

It seems like there's a problem with a label. Once I've removed it, the select control works as expected. It's definitely a bug we need to fix. Sorry for the inconveniences. See my snippet: https://mdbootstrap.com/snippets/jquery/s-kaczmarek/1295724


Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Open

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.10
  • Device: Thinkpad T480
  • Browser: Mozilla Firefox
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes