How to use SuggestionField with onBlur event

Hi team,

In Form, we have textfield with String value.
When a user type the text in input field, we get him the suggestion list:
User can choose value from dropdown list or he can get the input value that he was typed.
In project, we use SuggestionField and “enterPressHandler”

@Install(to = “suggestionField”, subject = “enterPressHandler”)
private void suggestionFieldEnterPressHandler(HasEnterPressHandler.EnterPressEvent enterPressEvent) {
suggestionField.setValue(enterPressEvent.getText());
}

But if user do not press ENTER on suggestionField, after input text then he click mouse on other component , unluck the suggestionField has clear text value.
image

We try to implement event Blur for SuggestionField , but not working:

@Subscribe
public void onInit(InitEvent event) {

    suggestionField.unwrap(FieldEvents.BlurNotifier.class).addBlurListener(event-> {
       //TODO somthing here
        notifications.create().withCaption("BlurNotifier:").show();
    });

}

get the error:
ClassCastException: Cannot cast io.jmix.ui.widget.JmixSuggestionField to com.vaadin.event.FieldEvents$BlurNotifier

Please help us in this case!

Hi,

Unfortunately the SuggestionField component doesn’t implement the FieldEvents.BlurNotifier interface. I’ve created an issue for this.

1 Like