Actions
Bug #9424
closedWComboBox 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 almost 3 years ago
- Status changed from New to InProgress
- Assignee set to Korneel Dumon
Updated by Korneel Dumon almost 3 years 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 Roel Standaert almost 3 years ago
- Target version changed from 4.6.1 to 4.6.2
Updated by Korneel Dumon almost 3 years ago
- Status changed from InProgress to Review
- Assignee deleted (
Korneel Dumon)
Updated by Roel Standaert almost 3 years ago
- Status changed from Review to Implemented @Emweb
- Assignee set to Korneel Dumon
Updated by Roel Standaert almost 3 years ago
- Status changed from Implemented @Emweb to Resolved
- % Done changed from 0 to 100
Updated by Roel Standaert over 2 years ago
- Status changed from Resolved to Closed
Actions