Skip to content

Commit

Permalink
cleaner schema fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Oct 17, 2023
1 parent e2e72cd commit b4754d6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/pages/data_submission/RegistrationValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export const compileSchema = (schema) => {
ajv.addFormat('date', dateValidator.isValid);
ajv.addFormat('uri', urlValidator.isValid);
ajv.addFormat('email', emailValidator.isValid);
const clone = Object.assign({}, schema);
delete clone['$schema'];
delete clone['version'];
return ajv.compile(clone);

// Ajv doesn't like the `$schema` and `version` properties
// eslint-disable-next-line no-unused-vars
const {$schema, version, ...obj} = schema;
return ajv.compile(obj);
};

/**
Expand All @@ -37,7 +38,16 @@ export const validateForm = (schema, formData) => {
return [valid, validation];
};

// Construct an object of the form: validation.`fieldName` { failed: ['required'], valid: true|false}
/**
* Construct a validation object of the form:
* {
* <fieldName>: { failed: ['required'], valid: true|false},
* <fieldName>: { failed: ['required'], valid: true|false},
* }
*
* @param errors Schema validation errors from Ajv
* @returns {{}}
*/
function errorsToValidation(errors) {
let validation = {};
if (errors !== null) {
Expand Down

0 comments on commit b4754d6

Please sign in to comment.