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

Lack of Explicit Custom Validation on Properties/Fields #573

Open
danieljancar opened this issue Oct 16, 2023 · 2 comments
Open

Lack of Explicit Custom Validation on Properties/Fields #573

danieljancar opened this issue Oct 16, 2023 · 2 comments
Labels
enhancement New feature or request Sponsorable If you need this feature, you can contact us for sponsoring it. Or submit a PR!

Comments

@danieljancar
Copy link

danieljancar commented Oct 16, 2023

Description

Hello everyone,
While FireCMS provides the ability to create custom fields by passing a React component to the fieldConfig prop, it lacks explicit documentation or features for adding custom validation logic to these fields. Correct me if im wrong. 😄

Example

Consider a scenario where we have a role field and an age field in the schema. The role field should only accept numbers that are multiples of 3, and the age field should only accept numbers between 18 and 60, inclusive.

role: {
    title: 'Role',
    dataType: 'number',
    validation: {required: true},
    // Hypothetical custom validation
    customValidation: (value) => {
        if (value % 3 !== 0) {
            return "Role number must be a multiple of 3";
        }
        return null;
    },
},
age: {
    title: 'Age',
    dataType: 'number',
    validation: {required: true},
    // Hypothetical custom validation
    customValidation: (value) => {
        if (value < 18 || value > 60) {
            return "Age must be between 18 and 60";
        }
        return null;
    },
},

Suggested Solution

Introduce a customValidation function property to the field definition, allowing developers to specify custom validation logic. This function could return a string to indicate a validation error or null if the value is valid.

Thank you for your feedback.

@fgatti675
Copy link
Member

Hi @danieljancar
Thanks for the suggestion, we are keeping this as a feature request

@fgatti675 fgatti675 added enhancement New feature or request Sponsorable If you need this feature, you can contact us for sponsoring it. Or submit a PR! labels Oct 20, 2023
@danieljancar
Copy link
Author

Hey @fgatti675,
Could I help implementing this feature or is it already worked on? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Sponsorable If you need this feature, you can contact us for sponsoring it. Or submit a PR!
Projects
None yet
Development

No branches or pull requests

2 participants