Relax JSON input validation
Currently the JSON form input validator only passes if the value is a
valid JSON string. This doesn't accout for cases where a paramater
doesn't need to be set. This patch relaxes the validation rule so it
also allows the value to be an empty string.
Change-Id: I4d135120ac3041b223986eef8f54c4de24f20379
Closes-Bug: #1645266
(cherry picked from commit 537618fed2
)
This commit is contained in:
parent
46c622c619
commit
933c1fe214
|
@ -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; }
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue