Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<AutocompleteArrayInput create> shows undefined on blur #8329

Closed
fzaninotto opened this issue Oct 28, 2022 · 0 comments · Fixed by #8331
Closed

<AutocompleteArrayInput create> shows undefined on blur #8329

fzaninotto opened this issue Oct 28, 2022 · 0 comments · Fixed by #8331
Assignees
Labels

Comments

@fzaninotto
Copy link
Member

fzaninotto commented Oct 28, 2022

What you were expecting:

When focusing then blurring an <AutocompleteArrayInput> with a create prop, the text I typed should be kept.

What happened instead:

The text is replaced by "undefined" instead.

Enregistrement.de.l.ecran.2022-10-28.a.12.37.04.mov

Steps to reproduce:

const choices = [
    { id: 'admin', name: 'Admin' },
    { id: 'u001', name: 'Editor' },
    { id: 'u002', name: 'Moderator' },
    { id: 'u003', name: 'Reviewer' },
];

export const CreateProp = () => (
    <AdminContext i18nProvider={i18nProvider}>
        <Create
            resource="users"
            record={{ roles: ['u001', 'u003'] }}
        >
            <SimpleForm>
                <AutocompleteArrayInput
                    source="roles"
                    choices={choices}
                    create={<CreateRole />}
                />
            </SimpleForm>
        </Create>
    </AdminContext>
);

// The create component doesn't matter, but here is one legitimate one
const CreateRole = () => {
    const { onCancel, onCreate } = useCreateSuggestionContext();
    const [value, setValue] = React.useState('');

    const handleSubmit = event => {
        event.preventDefault();
        const newOption = { id: value, name: value };
        choices.push(newOption);
        setValue('');
        onCreate(newOption);
    };

    return (
        <Dialog open onClose={onCancel}>
            <form onSubmit={handleSubmit}>
                <DialogContent>
                    <TextField
                        label="Role name"
                        value={value}
                        onChange={event => setValue(event.target.value)}
                        autoFocus
                    />
                </DialogContent>
                <DialogActions>
                    <Button type="submit">Save</Button>
                    <Button onClick={onCancel}>Cancel</Button>
                </DialogActions>
            </form>
        </Dialog>
    );
};

Environment

  • React-admin version: 4.4.4
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17
  • Browser: Chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant