firecms icon indicating copy to clipboard operation
firecms copied to clipboard

Lack of Explicit Custom Validation on Properties/Fields

Open danieljancar opened this issue 1 year ago • 2 comments

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.

danieljancar avatar Oct 16 '23 07:10 danieljancar

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

fgatti675 avatar Oct 20 '23 12:10 fgatti675

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

danieljancar avatar Jan 05 '24 14:01 danieljancar

Hi @danieljancar is this still something you need?

fgatti675 avatar Jul 03 '24 23:07 fgatti675

Hey @fgatti675, the feature would be a good addition, but I don't need it currently. 👍🏻 Thanks for asking 🙈

danieljancar avatar Jul 04 '24 13:07 danieljancar

Great, closing this for now :)

fgatti675 avatar Jul 04 '24 13:07 fgatti675