How to read value from mdb-select


Topic: How to read value from mdb-select

Tomasz Kisielewski asked 5 years ago

HTML

 <div class="col-sm-3">
    <select class="mdb-select md-form" searchable="Search here.." id="abc" data-placeholder="aaa" required>
       <option value="" selected disabled>Choose....</option>
      <option value="1">USA</option>
      <option value="2">Germany</option>
      <option value="3">France</option>
      <option value="3">Poland</option>
      <option value="3">Japan</option>
    </select>
    <label class="mdb-main-label">Label example</label>
                        </div>

JS

$('.mdb-select').materialSelect({
    validate: true,
    labels: {
      validFeedback: 'Correct choice',
      invalidFeedback: 'Wrong choice'
    }
});

$('#abc').change(function(e)
{
    e.preventDefault();
    var woj =$('#abc').val();
    alert(woj);
});

Click USA - return null
Click Germany - return null
Click France return 1
Click Poland return 2
???

As like there was a shift of val() by two positions


Grzegorz Bujański staff commented 5 years ago

Hi. Please update MDB to the latest version. I checked this on 4.13.0 and works fine.


Version 4.13.0
For this code works good

<div class="col-sm-3">
                    <select class="mdb-select md-form colorful-select dropdown-default" searchable="Wyszukaj"  id="abc" required>
   <option value=""></option>
  <option value="11">USA</option>
  <option value="21">Germany</option>
  <option value="31">France</option>
  <option value="41">Poland</option>
  <option value="51">Japan</option>
</select>
<label for="abc">Numer lokalu</label>
                    </div>

$('.mdb-select').materialSelect({
    validate: true,
    visibleOptions:-1,
    labels: {
      noSearchResults:'Nie znaleziono', 
      validFeedback: 'Correct choice',
      invalidFeedback: 'Wrong choice'
    }
});

but if you set placeholder

$('.mdb-select').materialSelect({
    validate: true,
    visibleOptions:-1,
    placeholder:'bla bla bla',
    labels: {
      noSearchResults:'Nie znaleziono', 
      validFeedback: 'Correct choice',
      invalidFeedback: 'Wrong choice'
    }
});

is not working properly
USA returns null
Germany nothing ( space ?)
France 11
Poland 21 etc

Additional mdb-main-label looks bad. it's a bit low

enter image description here


Grzegorz Bujański staff commented 5 years ago

We will fix it. For now you can set placeholder this way: <select class="mdb-select md-form colorful-select dropdown-default" data-placeholder='bla bla bla' searchable="Wyszukaj" id="abc" required>


This option also does not work - for USA returns empty as a result


Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.10.0
  • Device: PC
  • Browser: Firefox
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No
Tags