Project

General

Profile

Actions

Bug #9424

closed
AF KD

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

Bug #9424: WComboBox unexpectedly changes the current index after the model is reset.

Added by Andreas Frolov almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Korneel Dumon
Target version:
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
	});
}

KD Updated by Korneel Dumon almost 5 years ago Actions #1

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

KD Updated by Korneel Dumon almost 5 years ago Actions #2

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.

KD Updated by Korneel Dumon almost 5 years ago Actions #3

  • Target version set to 4.6.1

RS Updated by Roel Standaert over 4 years ago Actions #4

  • Target version changed from 4.6.1 to 4.6.2

KD Updated by Korneel Dumon over 4 years ago Actions #5

  • Status changed from InProgress to Review
  • Assignee deleted (Korneel Dumon)

RS Updated by Roel Standaert over 4 years ago Actions #6

  • Status changed from Review to Implemented @Emweb
  • Assignee set to Korneel Dumon

RS Updated by Roel Standaert over 4 years ago Actions #7

  • Status changed from Implemented @Emweb to Resolved
  • % Done changed from 0 to 100

RS Updated by Roel Standaert over 4 years ago Actions #8

  • Status changed from Resolved to Closed
Actions

Also available in: PDF Atom