Data Validators
In this section you will learn how to add validations to the Uploader schema fields.
Custom validation functions can be added to the schema fields in the code snippet directly. They can be added under the validator key. They should be async functions that accept a 2D array of strings as their only argument. This corresponds to the array of all inputs for all rows + columns provided by the user.Validation functions are called every time a user enters any input in the transform table even if the field that is being validated didn't change. This is done in order to facilitate contextual validation, where the validity of a field depends on the values of other fields.
Here's an example of a validation function that checks that the value of the first user-visible column does not equal "Bob":
1
{
2
"name": "name",
3
"displayName": "Name",
4
validator: async (rows) => {
5
return rows.map(row => {
6
if (row[0] === 'Bob') {
7
return {
8
errorMessage: 'Value must not be "Bob"'
9
};
10
}
11
12
return true;
13
})
14
}
15
}
Copied!
Note:
    The validation functions must return either an array of validation results for each row. The available validation outputs are a boolean true or false or an object with an errorMessage prop. true means that the row is valid, false means that it’s invalid with no error message, and `{ errorMessage: "custom error msg" }` is how you can provide custom error messages. They currently don’t display in the UI because we’re figuring out the best UI solution for that.
    Validation functions should not reject/throw errors. We make a best-effort attempt to catch the error, and if we do we ignore the custom validation function entirely and mark all rows as valid. Please use error handling within your validation functions to ensure that they don’t throw/reject.
    Validation functions only validate a single field, even though they are passed all columns for each row as input. If you want to validate multiple fields, add a validation function to each of the fields that you want to validate.
    You can run any code you want in the validation function including making network requests. However, if the validation function takes a long time to run, users will be prevented from continuing on with their transformation of the data until it returns.
Last modified 9d ago
Copy link