react-jsonschema-form
react-jsonschema-form copied to clipboard
Is there is a way to show default values for user?
Prerequisites
- [x] I have read the documentation
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 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.
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 ]
}
}
}