Using setVal on select not working the first time

I have a popup that contains a select where I want to select the entry by code before opening the popup.

The first time I do it and open the popup the entry is not selected in my select. If I close the popup and reopen it, the setVal is working.

Any idea on why I have this behaviour ?


Hello @Julien :wave:

Can you clarify the framework that you are using?

Also, make sure to share some of your relevant code, so we can see the exact usage.


I’m using mobiscroll 5.16, javascript version.

Based on this sample Javascript Event calendar Add/edit/delete events Example | Mobiscroll

When I create or edit an event the popup is opened, start and end datetime are hydrated and I try to do the same for the select but it doesn’t work the first time.

self.popup = mobiscroll.popup('#event-popup', {
    display: 'anchored',
    contentPadding: false,
    showArrow: false,
    onClose: self.onClose,
    onOpen: self.onOpen

self.employees ='#employees-list', {
    selectMultiple: true,

self.onOpen = function (args, inst) {
    // We have to call enhance because we are loading the fragment later with an xhr request
    mobiscroll.getInst(self.allDaySwitch).checked = self.actualEvent.allDay || false;
    self.range.setVal([self.actualEvent.start, self.actualEvent.end]);

    self.client.getParticipants(self.requestId).then(data => {
          let participants = => {
          let employee = {};
          employee.text =;
          employee.value =;
          return employee;
      self.employees.setOptions({data: participants});

    let selected = [];
    if (self.actualEvent.resource.constructor === Array) {
        selected = self.actualEvent.resource;
    } else {


I can’t reproduce the full issue, but I think we can start with this :

Look at the button click code, we use setVal and after we console.log(select.getVal())

The console shows an empty array the first time, close the popup reopen it, the console will show the selected values.


    <link rel="stylesheet" href="mobiscroll.min.css" />
    <script src="mobiscroll.javascript.min.js"></script>

    <button mbsc-button id="btn-open">Open</button>
    <div id="my-popup">

        <div class="mbsc-form-group">
            <input mbsc-input id="country-list" data-tags="true"/>

        const popup = mobiscroll.popup('#my-popup', {
            display: 'center'

        const select ='#country-list', {
            selectMultiple: true,

            .addEventListener('click', function () {
                    data: [
                        { value: 'atl', text: 'Atlanta'},
                        { value: 'ber', text: 'Berlin'},
                        { value: 'bos', text: 'Boston'},
                        { value: 'chi', text: 'Chicago'},
                        { value: 'lon', text: 'London'},
                select.setVal([ 'atl', 'ber' ]);


Ok I found the problem, a part of my code was not in the last block of my promise but outside.

It works well, sorry for that.