I am using the Parse function to parse a JSON string input into a JSON object before validating. Per the docs, the Parse function takes a callback with the value to be parsed as the first argument and the FieldContext as the second: https://vinejs.dev/docs/schema_101#parsing-input-value
When a valid JSON string is inputted, the parse function return JSON as expected. However, when attempting to report an error from inside the parse callback by using FieldContext.report, it reveals that the second argument is not an instance of FieldContext because the Report function is not available.
How can I report an error from inside the Parse function?
static tags = vine.array(vine.string().minLength(1).maxLength(64)).parse(this.jsonParse);
static jsonParse(value, field) {
console.log(test);
if(typeof(value) == "object") {
return value;
} else {
try {
return JSON.parse(value);
} catch(error) {
field.report(
"The {{ field.name }} field is not valid JSON",
"JSON",
field
);
return null;
}
}
}