Reputation: 1416
I m using react-jsonschema-form generator with NJsonSchema. After submit form i record json output and i want to use form for edit with submitted data any time. But i cannot find a way create the form with submitted data before. After try some json schema updates, I realize, the value keys in json not for filling inputs.
"Age": {
"value": "34",
"type": "integer",
"format": "int32"
}
here is react render code :
render((
<Form schema={schemaTest}
uiSchema={uiSchema}
onChange={log("changed")}
onSubmit={log("submitted")}
onError={log("errors")} />
), document.getElementById("app"));
is there any way filling inputs with json data, while form creating.
Upvotes: 2
Views: 2201
Reputation: 1416
I resolved it. react-jsonschema-form has formData prop. https://react-jsonschema-form.readthedocs.io/en/latest/api-reference/form-props/#formdata
Often you'll want to prefill a form with existing data; this is done by passing a formData prop object matching the schema.
Upvotes: 2
Reputation: 1
Try to set the values in states. Then try to put those states to each fields "default" properties.
Eg: "Age": { "value": "34", "type": "integer", "format": "int32", "default":this.state.formdata.age }
Upvotes: 0