Bug #9424
WComboBox unexpectedly changes the current index after the model is reset.
Start date:
12/01/2021
Due date:
% Done:
100%
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 }); }
Updated by Korneel Dumon over 1 year ago
- Status changed from New to InProgress
- Assignee set to Korneel Dumon
Updated by Korneel Dumon over 1 year 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.
Updated by Korneel Dumon about 1 year ago
- Status changed from InProgress to Review
- Assignee deleted (
Korneel Dumon)
Updated by Roel Standaert about 1 year ago
- Status changed from Review to Implemented @Emweb
- Assignee set to Korneel Dumon
Updated by Roel Standaert about 1 year ago
- Status changed from Implemented @Emweb to Resolved
- % Done changed from 0 to 100