sap.m.ComboBox - value is cleared, but item is still selected - combobox

I have a strange issue with ComboBox:
The control is located in xml fragment, inside sap.m.IconTabFilter.
I select a value in the combobox, then select another IconTabFilter.
Then I return to the previous tab, where the combobox is located.
The value of the combobox is cleared (I see a placeholder again), but when I open the dropdown menu of the combobox, I see that the item I have selected previously is highlighted and I can't select it again, like it's already been selected.
No function runs when switching tabs, no models are refreshed.
I tried to reproduce the issue, but my new code snippet works fine - the value is not cleared when I switch tabs.
What could it be?
Here is one of the ComboBoxes' definition:
<ComboBox id="comboid" items="{path: 'modelName>/'}" placeholder="{i18n>select}" selectionChange="onChange" customData:userProfileSetting="userId">
<core:Item text="{modelName>ID} {modelName>VALUE}" key="{modelName>ID}"/>
</ComboBox>

The root of problem was the low version of sapui5.
After upgrading from 1.28.4 to 1.28.44 (I'm limited to 1.28) it works fine.

Related

How to select an element from a ComboBox menu using Vaadin Testbench?

I am doing some integration tests with vaadin version 7.6.4 and Testbench (4.0.3).
I have a view with several comboboxes. One of them has this property comboBox.setTextInputAllowed(false); For testing purposes, I want to change the default value on the combobox and I need to select a different element then the default one.
To select an element I have tried the following code:
$(ComboBoxElement.class).selectByText("ElementName");
But this only works when comboBox.setTextInputAllowed(true);
I also have tried to use sendkeys() to change the selected value:
$(ComboBoxElement.class).openPopup();
$(ComboBoxElement.class).sendKeys(keys.ARROW_DOWN);
$(ComboBoxElement.class).endKeys(Keys.ENTER);
This code opens the comboBox popup correctly but doesn't select any item. Neither if I set the focus with setFocus();
Could anybody please tell me how can I change the value of a combobox with property setTextInputAllowed(false)?.
Indeed, your scenario does not seem to work as expected, at least with Vaadin 7.7.3 & TB 4.1.0.alpha1 I had.
Looking at the sources (line 43 atm), in the particular case when a combo is read-only, TestBench will make it writeable, send the specified text, and pick the corresponding item from the popup suggestion list. Nonetheless, during a small debug session, you can easily see that text.equals(popupSuggestions.get(0) is not equal to Region - 5 as they were hoping.
In conclusion, there's a chance that this is a bug in TB itself. I have a few suppositions but I did not have the time to investigate thoroughly atm how and why.
As a workaround, you can open the popup, use an XPath expression to find the correct item and click it. I have a demo app with a combo containing items named Region - 1 to Region - 10.
To select Region - 5 I did:
#Test
public void shouldOpenGridColumnVisibilityPopupAndSelectItems() {
getDriver().get("http://localhost:8080/");
ComboBoxElement combo = $(ComboBoxElement.class).first();
combo.openPopup();
findElement(By.xpath("//*[#id='VAADIN_COMBOBOX_OPTIONLIST']//span[text()='Region - 5']")).click();
}
Result:

Combobox List passing string

I have a VB6 application that has been running for quite sometime. Currently I'm trying to update one of the form that has a combobox 2.0. Because the combobox is populated with hundreds of items - I'm trying to update it so that users are able to click on a look up button next to it, where another window opens up with all the items from the combobox. User will be able to search by keyword and/or select an item and double click on it and have it appear in the combobox. The issue I'm having is with trying to pass no value or "" when CANCEL is clicked. I'm able to pass the value if I in the properties window my STYLE Is set to COMBO rather than list. However, the issue I come across is that with COMBO the value (text) in the combobox sometimes is not aligned properly. Is there a way to pass a "" value to a combobox 2.0 without changing the style to COMBO?
If they hit cancel set the ListIndex of your combo to -1 rather than setting the text property. This is the value for no item being selected.

How to set a prompt for combobox with mixed items?

There are nice solutions to the problem with combobox and prompt in WPF, but in my case I have mixed items -- image and text. So for example this solution (copied from https://stackoverflow.com/a/11671997/210342):
<ComboBox Name="MyComboBox"
IsEditable="True"
IsReadOnly="True"
Text="-- Select Team --" />
works fine as for prompt, but it has side effect, that when I select an item, the item in turn is not displayed correctly as selected -- it is presented in list OK, but after selection all combobox shows is System.Windows.Controls.ComboBoxItem.
So how to have a prompt (I don't insist of fixing this approach) and properly displayed mixed items?
I solved this in ugly way. I added a grid, put this combobox in the grid with ZIndex=0. I added extra button to the grid with ZIndex=1. This way I get an overlay. Any time users clicks on the button (combo is initially hidden) I open combobox programatically. When users selects anything from dropdown list of the combobox I hide the prompt button.

WPF Exiting "Dropped" Combobox, Items no longer editable?

Friends,
I have a WPF Combobox. When the Combobox is opened, I have the items dynamically generated based upon environment variables. So basically a combobox that is bound to a list that is dynamically changing.
Everything works as expected until I Exit the combobox with the dropdown open to enter another control(another combobox).
When I reopen the first combobox, the items appear to be frozen and no longer bound to the list when INDEED the list is changing and is still bound. Its almost like the binding broke.
When this event occurs, I have attempted to forcefully add items, and that doesn't work either. I can see in the code behind that the combobox now contains the additional items, yet it doesn't appear that contain them in the UI.
What is this black magic? Any way to prevent it? is this some type of Stuck focus issue? Maybe the dropdown isn't re-sizing?
I think i have narrowed it down to the physical dropdown is not re-sizing to the new items.
EDIT*
The controls are dynamically generating, so I have no real hard code to show you other than this.
private void CBControl_DropDownOpened(object sender, EventArgs e)
{
((ComboBox)sender).Items.Add("Option");
}
On this event, I will add an items to the combobox, although the items ARE being added to the list, they are not displayed in the UI.
EDIT 2*
I figured it out, so i have 2 comboboxes, it appears that the 2nd was steeling and holding the focus INSIDE the dropdown. (odd bug)
in order to fix it i needed to release it bu changing the index of the 2nd combo box WHILE it is open.
int sel = ComboBoxTwo.SelectedIndex;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = -1;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = sel;
and I had to manage the unintended recursive call.
So, here it is.
You got 2 ComboBoxes. If you Open one then directly click into another, the focus is moved to the second combobox dropdown.
If you make any changes to the first combobox, the changes will not take effect to the style(dropdown resize) UNTIL you release the focus from the 2nd combo box dropdown item. Although the items change will take effect, the resize wont.
to release the focus, you need to open the second combox and change the selected index like so:
int sel = ComboBoxTwo.SelectedIndex;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = -1;
ComboBoxTwo.IsDropDownOpen = true;
ComboBoxTwo.SelectedIndex = sel;
10 hours of debugging. 5 hours of research. First solution I have found. It may be dirty, but its all I can find.

ComboBox selection not reset to top of dropdown list (items) in javafx 2.2

I have a Source ComboBox to populate source fields (25-30 items) shown below in first page
"A"
"B"
...
"Z"
I have selected last item from ComboBox as shown below
"Z"
and when traversing to the next page after saving, i need to make the source combo selection blank, so i have return the below code to reset the Source combobox to point to first item (to reset the display to start from top of dropdown list for user selection)
// my first value in source List is empty space - “”
sourceComboBox.setValue("");
even if you use below code snippets like
sourceComboBox.getSelectionModel().selectFirst();
sourceComboBox.getItems().clear();
sourceComboBox.getSelectionModel().clearAndSelect(0);
but when i click open the combobox dropdown it still shows dropdown display from bottom as shown below
...
"X"
"Y"
"Z"
I am unable to post images for representing combobox values, so has put in above examples.
This looks like a graphics bug to me or am I doing something wrong?
I have seen similar issue reported in below question but no work around suggested so far
Combobox clearing value issue
If you want to simply "reset" the combo box, I think all you have to do is set the value to null, like so:
sourceComboBox.setValue(null);
I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:
sourceComboBox.getSelectionModel().clearSelection();
sourceComboBox.getItems.clear();
do something like this...
parentNode.getChildren().remove(sourceComboBox);
sourceComboBox= new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(sourceComboBox);
You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.
Below is the code you're looking for. It will reset it to whatever index you give in within the parenthesis.
sourceComboBox.setSelectedIndex(0);
Goodluck
Most of the things were giving me an error when I tried them. What worked best for me was to use this
comboBox.getSelectionModel.clearSelection();
This will essentially set the value of your ComboBox to null. Because of this, if you are referring to the value of the ComboBox in another place, it becomes important to check for whether the value of the ComboBox is null using this
if(comboBox.getValue() != null)
//Code segment here
The ComboBox control has not a method like scrollTo(index) of the ListView. So it seems hard to workaround that behavior. You can issue a feature request at JavaFX Jira.

Resources