react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Using getDefaultFormState with 'default' and 'const' values to override current formData

Open Bonfims opened this issue 7 months ago • 2 comments

Prerequisites

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?

Bonfims avatar Jul 15 '24 21:07 Bonfims