rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
13.92k stars 2.17k forks source link

How to add a custom field along with NumberField and BooleanField #4054

Open divya-sea opened 5 months ago

divya-sea commented 5 months ago

Prerequisites

What theme are you using?

other

What is your question?

I have a schema with a field named lastName, and the associated UI schema for this field includes a mapping ui:field: 'slider'. In my React JSON Schema Form wrapper, I am using the fields prop, which consists of BooleanField and NumberField components. However, I want to include an additional component, a slider, for the lastName field. Despite specifying the ui:field: 'slider' mapping, the NumberField component is consistently loaded because the type of lastName is number/integer. I am seeking guidance on how to override the NumberField component to render a different component, presumably the slider, for the number/integer type.

schema = properties: {
    firstName: {
      type: 'string',
      title: 'First name',
      default: 'Chuck',
    },
    lastName: {
      type: 'integer',
      title: 'Last name',
      minimum: 0,
      maximum: 100,
    },
  },

uischema

const uiSchema = {
  lastName: {
    'ui:field': 'slider',
  },
};

<Form
      {...args}
      fields={{
        BooleanField,
        NumberField,
        slider: () => {
          return <Loader percentage={percentage} type="linear" showPercentageText={true} />;
        },
      }}
    />
heath-freenome commented 5 months ago

@divya-sea Can you provide a codesandbox.io for what you are trying to do?