Skip to content

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

Open
@Bonfims

Description

@Bonfims

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions