react-jsonschema-form
react-jsonschema-form copied to clipboard
Using getDefaultFormState with 'default' and 'const' values to override current formData
Prerequisites
- [X] I have read the documentation
What theme are you using?
core
What is your question?
Hello!
I was trying to achieve an override-like functionality with getDefaultFormState
from the utils. For example:
const { validator } = require("...");
let newSchema = {
type: "object",
properties: {
field: {
type: "string",
default: "456",
const: "456"
}
}
};
let currentFormData = { field: 123 };
let formData = getDefaultFormState(validator, newSchema, currentFormData);
// This will return { field: 123 }
I was expecting it to return { field: "456" }
, assuming that the schema's property declarations (const
, default
and readOnly
) would override the current value.
Is there a way to achieve this?