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

Is there is a way to show default values for user?

Open thaikoh opened this issue 7 months ago • 2 comments

Prerequisites

What theme are you using?

material-ui

What is your question?

I want to display default fields values as a hint or help to a user. Is it possible to do? I'm using @rjsf/material-ui in my project.

thaikoh avatar Apr 09 '25 13:04 thaikoh

@thaikoh You have a lot of options.

You should take a look at the custom templates doc. You might decide to implement your own FieldTemplate, or ObjectFieldTemplate. You can use the core implementation or the MUI implementation as reference or starting point.

In my project we decided to override the BaseInputTemplate and make the default/const value the placeholder.

nickgros avatar Apr 11 '25 19:04 nickgros

You should be able to do this by specifying examples in the JSON schema without the need to modify the template.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "name": {
      "type": "string",
      "examples": [ "John Doe", "Jane Doe" ]
    },
    "age": {
      "type": "integer",
      "examples": [ 1, 18, 55 ]
    }
  }
}

jasny avatar May 07 '25 08:05 jasny