Created
February 25, 2018 17:19
-
-
Save droganov/461087e71a1c35e8aeb39140d4b24d61 to your computer and use it in GitHub Desktop.
This file contains 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
// Validator will pass a form to schema creator | |
export default form => ({ | |
type: 'object', | |
properties: { | |
text: { | |
type: 'string', | |
messages: { | |
type: 'Should be a string', | |
required: 'Please enter a text', | |
}, | |
}, | |
minimum: { | |
type: 'integer', | |
// form data can be used to set schema props explicitly | |
maximum: form.maximum, | |
minimum: 0, | |
messages: { | |
type: 'Should be a zero or more', | |
minimum: 'Should exceed 0', | |
}, | |
}, | |
maximum: { | |
default: null, | |
type: ['integer', 'null'], | |
minimum: { $data: '1/minimum' }, | |
// Messages key is not a part of json.org spec, | |
// but it is very useful in real life | |
messages: { | |
type: 'Should be a zero or more', | |
minimum: `Should exceed ${form.minimum || 0}`, | |
}, | |
}, | |
}, | |
required: ['text', 'minimum'], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment