Created
May 19, 2020 08:45
-
-
Save kingsleyzissou/207e3957095fb8c53d9b0fc55f08a13a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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