question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutocompleteInput does not display choices

See original GitHub issue

What you were expecting: I expected to enter a search string in the <AutocompleteInput/> and get autocomplete choices

What happened instead: The query returned a list of autocomplete options, but they were not displayed. Rather, they appear for a moment when I remove the focus from the field, then disappear.

Related code:

const TaskCreate = ({...props }) => {
  
    const controllerProps = useCreateController(props);

    return (
        <CreateView
            {...props}
            {...controllerProps}
        >
            <SimpleForm  >
            <ReferenceInput source="maintainableItem" reference="Object"  fullWidth >
                <AutocompleteInput />
            </ReferenceInput> 
            </SimpleForm>
        </CreateView>
    );
};

export default TaskCreate;

Other information: that’s what the react-admin does right after the page loads: Аннотация 2019-12-18 151207

response: Аннотация 2019-12-18 151517

then i enter the search text: Аннотация 2019-12-18 1515174

response: Аннотация 2019-12-18 15151а74

but nothing is displayed on the screen until I click on an empty spot: wfUqa2CtL2

after a moment, the autocomplete options disappear and the first 25 entries are displayed

Environment

  • React-admin version: 3.1.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wmwartcommented, Dec 18, 2019

Empirically, I have identified the problem. It was hard to guess.

If the optionText property (default “name”) does not contain a search string ({filter: { q: “d2he”}}), then the options are not displayed !!!

The {filter: { q: “d2he”}} does not have to return objects with the “name” field that contains the search string. For example, my backend allows me to search by id, but I do not want to return the id to the AutocompleteInput option, I want to display the name, and I can not do this.

  1. Open codesandbox
  2. Go PostCreate.js
  3. fix:
...
                            <ReferenceInput
                                label="User"
                                source="user_id"
                                reference="users" 
                            >
                                <AutocompleteInput optionText="role"/>
                            </ReferenceInput>
...
  1. Add Authors
  2. Search “Lo” (Logan Schowalter)
0reactions
fzaninottocommented, Dec 19, 2019

The AutocompleteInput does filtering on the client-side, and the ReferenceInput does filtering in the server side. Even though the AutocompleteInput does receive options, the ReferenceInput won’t display them if the optionText does not match the typed string.

That’s what matchSuggestion is for. It’s a function which check whether a choice matches a filter. It must return a boolean.

(filter: string, suggestion: any) => boolean

It’s documented in the properties of the AutocompleteInput: https://marmelab.com/react-admin/Inputs.html#autocompleteinput.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AutocompleteInput suggestions are not working - Stack Overflow
It's simply not working. Typing in the AutocompleteInput will not filter the choices to select from for either consumers or providers.
Read more >
The AutocompleteInput Component - React-admin - Marmelab
Tip: <AutocompleteInput> is a stateless component, so it only allows to filter the list of choices, not to extend it. If you need...
Read more >
Autocomplete | Angular Material
Start by creating the autocomplete panel and the options displayed inside it. Each option should be defined by a mat-option tag.
Read more >
Autocomplete API - Material UI - MUI
Name Type Default options * array renderInput * func autoComplete bool false
Read more >
Widgets and DOM elements — Bokeh 3.0.3 Documentation
Widgets are interactive control and display elements that can be added to Bokeh ... The AutocompleteInput widget is a general-purpose text input widget...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found