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

Add unique validator #8999

Merged
merged 16 commits into from
Jun 16, 2023
Merged

Add unique validator #8999

merged 16 commits into from
Jun 16, 2023

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Jun 12, 2023

Validating the uniqueness of a field is a common requirement so we'd like to provide the useUnique hook that returns a validator for this use case.

It will call the dataProvider.getList method with a filter to check whether a record exists with the current value of the input for the field matching the input source.

Basic usage (more options in the documentation):

const UserCreateForm = () => {
    const unique = useUnique();
    return (
        <SimpleForm>
            <TextInput source="username" validate={unique()} />
        </SimpleForm>
    );
};

djhi added 2 commits June 12, 2023 18:12

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
@djhi djhi added WIP Work In Progress and removed RFR Ready For Review labels Jun 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@djhi djhi added RFR Ready For Review and removed WIP Work In Progress labels Jun 13, 2023
@fzaninotto
Copy link
Member

You should update the doc sidebar to add an entry for the new useUnique hook.

Co-authored-by: Francois Zaninotto <francois@marmelab.com>
Co-authored-by: Jean-Baptiste Kaiser <jb@marmelab.com>
@fzaninotto fzaninotto merged commit 5dedc3a into next Jun 16, 2023
@fzaninotto fzaninotto deleted the unique-validator branch June 16, 2023 13:43
@fzaninotto fzaninotto added this to the 4.12.0 milestone Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants