Project

General

Profile

Bug #9424

WComboBox unexpectedly changes the current index after the model is reset.

Added by Andreas Frolov about 2 months ago. Updated 24 days ago.

Status:
InProgress
Priority:
Normal
Assignee:
Target version:
Start date:
12/01/2021
Due date:
% Done:

0%

Estimated time:

Description

Hello,

Consider the following example. After the model is filled, the current index is explicitly set to -1. Nevertheless, at the next event loop, Wt changes the index to 0.

Application::Application(const Wt::WEnvironment& env) : Wt::WApplication(env)
{
    auto comboBox = root()->addWidget(std::make_unique<Wt::WComboBox>());
    comboBox->setNoSelectionEnabled(true);

    auto model = std::make_shared<Wt::WStringListModel>();
    comboBox->setModel(model);

    auto button = root()->addWidget(std::make_unique<Wt::WPushButton>("Reset ComboBox"));

    button->clicked().connect([model, comboBox]() {
        model->setStringList({ {"blah"} });
        Wt::WTimer::singleShot(std::chrono::milliseconds(0), [comboBox]() {
            int currentIndex2 = comboBox->currentIndex(); // currentIndex2 is 0 ???
        });
        comboBox->setCurrentIndex(-1);
        int currentIndex1 = comboBox->currentIndex(); // currentIndex1 is -1
    });
}
#1

Updated by Korneel Dumon about 2 months ago

  • Status changed from New to InProgress
  • Assignee set to Korneel Dumon
#2

Updated by Korneel Dumon about 2 months ago

Apparently, the index -1 must be explicitly set after rerendering the WComboBox contents. This was an easy fix, but another issue remains.

When the reset-button is clicked, the JS update is something like this:

Wt._p_.addTimerEvent('o1x', 0,-1);
setTimeout(function() { j4.selectedIndex=-1;}, 0);
Wt4_6_0.setHtml(j4,'<option value="0">blah</option>');

The timer event will run before the code that sets the index to -1, so it will report index 0.

#3

Updated by Korneel Dumon about 2 months ago

  • Target version set to 4.6.1
#4

Updated by Roel Standaert 24 days ago

  • Target version changed from 4.6.1 to 4.6.2

Also available in: Atom PDF