Skip to content

Consider moving omit extra data functionality to schemaUtils #4081

@MarekBodingerBA

Description

@MarekBodingerBA

Prerequisites

What theme are you using?

core

What is your question?

Hello,

Due to the advanced way in which we use RJSF, we need to programmatically omit extra data. We have implemented our own step functionality on top of RJSF, and we need to filter out extra data without submitting the form when switching between steps, as liveOmit is hitting our performance requirements.

Temporarily, we have created a custom function that mimics the logic from here and here:

function omitData(schema: RJSFSchema, formData: RJSFSchema) {
  // rjsfValidator and defaultFormStateBehavior are shared consts
  const schemaUtils = createSchemaUtils(rjsfValidator, schema, defaultFormStateBehavior)
  const formInstance = new Form({ schema, validator: rjsfValidator })

  const retrievedSchema = schemaUtils.retrieveSchema(schema, formData)
  const pathSchema = schemaUtils.toPathSchema(retrievedSchema, '', formData)
  const fieldNames = formInstance.getFieldNames(pathSchema, formData)

  return formInstance.getUsedFormData(formData, fieldNames)
}

Using new Form in this manner is entirely possible, as neither getFieldNames nor getUsedFormData access this. However, it is clear that this is not the best long-term solution. The extraction could be beneficial for other users and would help to avoid duplicating the same logic if it were centralized. Would schemaUtils be an appropriate place for this? A similar function, getDefaultFormState, already exists there.

I propose the following:

  1. Move getFieldNames and getUsedFormData to a separate context, as they are used exclusively by the omit logic.
  2. Move the omit logic in both locations to schemaUtils.omitExtraData and replace its usage in the Form.
  3. Update the tests and documentation accordingly.

I can work on this if you give me the green light to proceed.

Thanks!

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