这是indexloc提供的服务,不要输入任何密码
Skip to content

SearchField Suggest All When Empty #219

@yetyman

Description

@yetyman

Suggesting an enhancement.

I am using the SearchField and would like to know if there is a way to get the suggestions to appear with a user text of an empty string?

In my application a long list of options is available but I would not expect a user to know which option they would like before they start typing in all situations. Rather than trying every letter of the alphabet first, it would be nice if while focused/typing cursor, the suggestions popup is visible with whatever results the suggestion provider gives for the empty string in the typing area.

Could a property be added for this? Something like "suggestWhenBlank". Here are where I believe it would need to be to affect this functionality. Not all blank text checks need it.

around line 229 of SearchField

    editor.textProperty().addListener(it -> {
        if (!committing) {
            if (StringUtils.isNotBlank(editor.getText()) || suggestWhenBlank.get()) {
                searchService.restart();
            } else {
                update(null);
            }
        }
    });

around line 640 of SearchField

        if (!isCancelled() && (StringUtils.isNotBlank(searchText) || suggestWhenBlank.get())) {

around line 50 of SearchFieldPopup

        if ((!searchField.getSuggestions().isEmpty() || searchField.getPlaceholder() != null) && (StringUtils.isNotBlank(searchField.getEditor().getText()) || searchField.suggestWhenBlank.get())) {

along with this comes the behaviour of showing results before typing has started and for that I would change around line 158

        if (!editor.isFocused()) {
            // Add the current text to the history if the editor lost focus.
            if (isAddingItemToHistoryOnFocusLost()) {
                addToHistory(editor.getText());
            }
            commit();
            if (getSelectedItem() == null) {
                editor.setText("");
            } else {
                invokeCommitHandler();
            }
        }
        else if (suggestWhenBlank.get() || StringUtils.isNotBlank(editor.getText())) {
            searchService.restart();
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions