jsoneditor icon indicating copy to clipboard operation
jsoneditor copied to clipboard

Change Json schema validation error message

Open AdityaPratap1 opened this issue 3 years ago • 1 comments

Hello,

Is there a way to change the validation error message instead of using the default message? Here is what I have tries so far:

onValidationError: function (errors) {
        console.debug(errors)            
        errors.forEach((error) => {
          switch (error.type) {
            case 'validation': // schema validation error
                   if(error.schemaPath === "someIdentifier") {
                      error.message = "Custom Message";
                   }
              break;
            case 'customValidation': // custom validation error
              break;
            case 'error':  // json parse error
              break;
          }
        });


      },

The custom message is not reflected in the json editor. Any help would be appreciated!

Thank you!

AdityaPratap1 avatar Jun 29 '22 23:06 AdityaPratap1

The onValidationError callback is only to get notified about the errors, it cannot be used to change the erorrs.

You can probably use onValidate(json) to roll your own validation the way you like (including using the latest version of the ajv valiator). Here is an example: https://github.com/josdejong/jsoneditor/blob/develop/examples/18_custom_validation.html

josdejong avatar Jun 30 '22 06:06 josdejong