react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

AutocompleteInput createLabel prop does not work.

Open davidhenley opened this issue 1 year ago • 2 comments

Either the docs need to be updated or the functionality needs to be added.

We still REALLY need this functionality for our office applications as it is not apparent that you can start typing to create a new item. 🤞

https://github.com/marmelab/react-admin/issues/7822

https://marmelab.com/react-admin/AutocompleteInput.html#create

CleanShot 2024-01-25 at 21 20 31@2x

davidhenley avatar Jan 26 '24 03:01 davidhenley

I agree with you, this prop does not work as described so we should fix either the docs or the code.

In the meantime, maybe this can help? (from the section at the very bottom of the AutocompleteInput docs)

The Create %{item} option will only be displayed once the user has already set a filter (by typing in some input). If you expect your users to create new items often, you can make this more user-friendly by adding a placeholder text like this:

const PostCreate = () => {
    const categories = [
        { name: 'Tech', id: 'tech' },
        { name: 'Lifestyle', id: 'lifestyle' },
    ];
    return (
        <Create>
            <SimpleForm>
                <TextInput source="title" />
                <AutocompleteInput
                    onCreate={(filter) => {
                        const newCategoryName = window.prompt('Enter a new category', filter);
                        const newCategory = { id: categories.length + 1, name: newCategoryName };
                        categories.push(newCategory);
                        return newCategory;
                    }}
                    source="category"
                    choices={categories}
+                   TextFieldProps={{
+                       placeholder: 'Start typing to create a new item',
+                   }}
                />
            </SimpleForm>
        </Create>
    );
}

slax57 avatar Jan 26 '24 09:01 slax57

Thank you!

davidhenley avatar Jan 26 '24 15:01 davidhenley