How to validate fields format

Field validations

Field validation has a lot of operators for handing dates and number fields, which are fine. But thats not good enough to make ANOTHER type of fields validations


If we want to validate if input field is a ā€¦ url, there is no way to do that. OF COURSE we can use hooks, but hooks problem is ā€¦ we dont see the error in the FIELD that causes it.

Proposal ?

Let addFieldValidation function to receive a validation function. That validation function can receive field value and return ā€¦ I dont know, an exception, or success and failure, with an specific error message to display in the UI. Something like this:

collection.addFieldValidation('fieldName', (fieldValue:any) => {
  // Perform my validations here ... and, if value is invalid ...
  throw new InvalidField('I dont like you, Field')

Hi @Maximiliano_Carrizo :wave: here we have some wanted limitation. The addFieldValidation function add a validator transmitted to the UI. For many reasons we have limited this feature to operators known by the UI.
As a workaround, like you said, you can create update hook with specific error message as below:

.addHook('Before', 'Update', context => {
  if (!isURL(context.patch.fieldName)) {
    context.throwValidationError('FieldName is not a valid URL!');

Let me know if that help :pray:

1 Like

Yeah ā€¦ Im already using hooks for validations, but ā€¦ showing the errors in the bottom of the page is not the same thing that showing the errors on the fields itself.

Yeah, its fine. Its not a big deal. Thanks, Arnaud.

I know what you mean, and Iā€™m gonna to push your feedback as feature request on our product board.

Thanks, Arnaud. It would be great !