Topic: Selected show impossible

Scal68 pro asked 5 years ago


Hello, I just installed version 8.4 jquery and I can not display an option selected after a build of my select ajax. Can you help me ?


Bartłomiej Malanowski staff commented 5 years ago

What's your code? How can we reproduce your issue?


Tomek Makowski staff answered 5 years ago


So then try this script

    $(document).ready(function () {
    $('.mdb-select').materialSelect();

    $(".mdb-select option[selected]").each(function(){
      let val = $(this).val();
      $(this).parents(".mdb-select").prev().find("li").eq(val-1).click();
    }); 
  });

Scal68 pro answered 5 years ago


Hello I just found that if you put the select twice, the second selected does not work. So if there is more on the page, only the first works.


Tomek Makowski staff answered 5 years ago


You are welcome :D .


Scal68 pro answered 5 years ago


It works, I do not know why it did not work yesterday. thank you so much


Tomek Makowski staff answered 5 years ago


Scal68 pro answered 5 years ago


Hello Thanks for your help. I still have the problem with the label that does not move places. I have placed your code in my jquery script. see the picture below

enter image description here


Tomek Makowski staff answered 5 years ago


Hi

Try this out

const val = $(".mdb-select option[selected]").val();
$(".mdb-select").prev().find("li").eq(val-1).click();

best, Tomek


Scal68 pro answered 5 years ago


Hello Thanks for your help. If we take your example with the label and add selected to option 3, it does not appear at the top of the menu. Against if we remove the label it works. Is this normal?

 <select class="mdb-select md-form colorful-select dropdown-primary">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3" selected>Option 3</option>
  <option value="4">Option 4</option>
  <option value="5">Option 5</option>
</select>
<label class="mdb-main-label">Blue select</label>


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

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.4
  • Device: php jquery ajax
  • Browser: firefox
  • OS: win 10
  • Provided sample code: No
  • Provided link: No