diff --git a/src/js/components/utils/Formsy.js b/src/js/components/utils/Formsy.js index d0f896d5..b4fac027 100644 --- a/src/js/components/utils/Formsy.js +++ b/src/js/components/utils/Formsy.js @@ -4,8 +4,12 @@ import Formsy from 'formsy-react'; * Custom validation rules used throughout the app. */ export default function initFormsy () { - Formsy.addValidationRule('isJson', (values, value) => { - try { return !!JSON.parse(value); } + /* + * The field is valid if the current value is either empty + * or a valid JSON string. + */ + Formsy.addValidationRule('isJson', (values, value, otherField) => { + try { return value === '' ? true : !!JSON.parse(value); } catch(e) { return false; } }); }