Skip to content

Instantly share code, notes, and snippets.

@kingsleyzissou
Created May 19, 2020 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingsleyzissou/207e3957095fb8c53d9b0fc55f08a13a to your computer and use it in GitHub Desktop.
Save kingsleyzissou/207e3957095fb8c53d9b0fc55f08a13a to your computer and use it in GitHub Desktop.
import Ajv from 'ajv';
import { JSONSchemaBridge } from 'uniforms-bridge-json-schema';
const ajv = new Ajv();
ajv.addFormat('date-time', {
validate: (dateTimeString) => {
console.log('here', dateTimeString);
return dateTimeRegex.test(dateTimeString);
}
});
function createValidator(schema) {
return model => {
const validator = ajv.validate(schema, model);
if (validator.errors && validator.errors.length) {
throw { details: validator.errors };
}
};
}
const schema = {
type: 'object',
properties: {
date: {
type: 'string',
format: 'date-time',
title: 'date',
uniforms: {
title: 'Date',
type: 'datetime-local'
}
},
},
required: [
'date'
]
};
const schemaValidator = createValidator(schema);
export default new JSONSchemaBridge(schema, schemaValidator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment