53js / react-jsonschema-form-validation Goto Github PK
View Code? Open in Web Editor NEWSimple form validation using JSON Schema and AJV
Home Page: https://53js.github.io/react-jsonschema-form-validation
License: MIT License
Simple form validation using JSON Schema and AJV
Home Page: https://53js.github.io/react-jsonschema-form-validation
License: MIT License
Hi!!
I can get the context:
import { Form, useFormContext } from 'react-jsonschema-form-validation';
const context = useFormContext()
context is always
undefined
Any idea? I wonder if there is something related with webpack and default exports.
memoGetOnChangeHandler = memoize((onChange, handleFieldChange) => (event) => {
if (onChange) {
// Pass Form.handleFieldChange handler as extra parameter to the onChange handler
onChange(event, handleFieldChange);
return;
}
handleFieldChange(event);
})
this is onChange handler from Field.js. It passes further only first argument 'event' from component, but e.g. react-select passes the second param https://react-select.com/props.
I am trying to wire the submit button the the Form
component's valid
state. In other words, the goal is to keep the button disabled until the form satisfies all validity constraints.
My current implementation is based on React references and, as expected, works unsatisfactorily due to the asynchronous nature of the process. There is no guarantee that the valid
state of the Form
component is updated by the time setState
is run in the parent component:
this.FormRef = React.createRef(null);
handleChange = (data) => {
this.setState({
formData: data,
success: false,
invalid: !this.FormRef.current.state.valid
})
}
...
<Form
ref={this.FormRef}
…
>
…
</Form>
ReactJS is still somewhat out of my depth, but I wonder whether the Form
component could be tweaked to expose its valid
state more reliably and painlessly—for instance by passing valid
as a prop to the onChange callback, or including it in form data, or by not triggering the onChange
handler until the state has been updated.
Thanks for your help and for a fantastic library.
The debug flag is prefixed with REACT_APP_... so it is adapted to cra but not for other build tools such as gatsby which requires env variables to be prefixed with GATSBY_ to be available client-side.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.