score:3
Accepted answer
If you want to track form changes, you can handle it without settingState on every change, instead you can setState on Submit. If you want to pass formData programmatically you can use something as following:
this.state = {
formData : {
firstname:'Test first name'
}
}
Following code works as you expect: (https://jsfiddle.net/tpjL2z06/)
const Form = JSONSchemaForm.default;
const schema = {
title: "Test Form",
type: "object",
properties: {
firstname: {
type: "string",
title: "firstname"
},
}
};
const uiSchema = {
firstname : {
"ui:widget": (props) => {
return (
<div>
<input type="text"
value={props.value}
required={props.required}
onChange={(event) => props.onChange(event.target.value)} />
</div>
);
}
}
};
class App extends React.Component {
constructor(props){
super(props)
this.state = {
formData : {}
}
}
render() {
return (
<div className="App">
<div>
<Form
schema={schema}
uiSchema={uiSchema}
formData={this.state.formData}
onSubmit={(data)=>{ console.log(data) }}
/>
</div>
</div>
);
}
}
ReactDOM.render(<App />, document.querySelector("#app"))
Source: stackoverflow.com
Related Query
- Custom widget with input loses focus in react-jsonschema-form when formData is passed as a prop to the form
- React useState hooks - Text input loses focus when typing if passing form through props
- React Hooks - Input loses focus when 1 character is typed in
- React text input loses focus when I type a letter
- How to scroll to text input on focus when there is an input accessory with React Native
- React - Draggable components with inputs lose the ability to focus when clicking that input
- React - Material UI - TextField controlled input with custom input component not working properly losing focus
- why does focus loose from the html input element when i return input component from custom React Hooks?
- Solved: React-day-picker Daypicker Input loses focus when using custom input component
- How to create a signup form with React and Why won't a function be executed when called insight a form after input field?
- Custom React component doesn't show input length when used with react-hook-form
- React input loses focus when user types into it
- react-day-picker custom input loses focus when onDayChange selects a day
- React - Input loses focus after typing 1 char in dynamic form
- I have issue with React forms when I try to post form with file type input
- Custom input component with React Hook Form 7
- React Material ui FilledInput cannot focus input when change state with onFocus event
- Implement a clear button for a custom input field to trigger required error with react hook form
- React - Input loses focus when setState is called on a completely different component
- React prevent form submission when enter is pressed inside input
- Clear form input field values after submitting in react js with ant-design
- Form fields lose focus when input value changes
- React Native requires two taps to change input focus when within scrollview
- react input field will loose focus when filtering data
- React rebuild tree with HOC components (causing input field focus loss)
- React - input loses focus on keypress
- How to create dynamic form input fields in React with ANTd
- Change focus of text input with react
- how to set focus to next input on enter key press in react js with refs
- React form triggers button onClick with every input
More Query from same tag
- Setup nginx with react and express
- Can't get CORS working in ReactJS Application with nginx
- function variable not being passed to setState correctly
- Pagination numbers not visible in reactjs
- Uncaught TypeError: this is undefined in Amplify UI in React
- Cannot import react js component
- Typescript: How to add property ‘types’ to function returned from React.forwardRef
- 'Missing initializer in const declaration.' error in React
- ReactJS:setState could not work in Syncfusion React Toast
- How to hide parent component when routing to nested path v6 reactjs?
- How to use a callback in a render() of React component
- initialize state react, to solve undefined when the page first rendered
- TypeError: Cannot read property 'characters' of undefined
- Connecting two contexts return undefined values in the consumer context react hooks
- Cypress with MeteorJS: user does not stay logged in
- Disable submit button if field is empty
- import javascipt jquery file in to react file
- Pass value from server side to client side in Next JS using getInitialProps
- Rails is seeing a post request as a get, with a react front end
- Warning: Prop `className` did not match ~ Material UI css arbitrarily breaks on reload
- How to handle loading redux state of single items to show a loading indicator
- How to create a generic arrow function with react and typescript
- extends RouteComponentProps to accept more props?
- React rendering a loop inside a loop
- Filter nested object in ReactJS
- Scroll to top on every transition react-router-dom v6
- Each child should have a unique key prop even they're set - REACT
- Form submission with redux-saga
- Need to render a sidebar component onclick() from another component
- Is there a way to trigger Material-UI Modal close manually