Hello everyone, Does anyone know how I can verify that the form is valid? I…
July 1, 2019 at 6:08pmHello everyone, Does anyone know how I can verify that the form is valid? I look in the examples and I do not see an example of validation. First of all, Thanks.
July 1, 2019 at 6:08pmJuly 2, 2019 at 7:39am
What exactly are trying to do? I suppose you are not looking for something like demonstrated in the person example (https://jsonforms.io/examples/person), where errors are just displayed beneath the form?
July 2, 2019 at 3:10pm
July 3, 2019 at 7:59am
Hi Salim. Did you see this answer? I think it should answer your question here.
July 3, 2019 at 4:14pm
yes but the problem I have is that in the application example that I download on the page, I do not know how to access the variable "store" from the App.tsx file, which is where I have the function when I click. the variable "store" is accessible is from the file index.tsx, I really apologize in advance, it must be because of my lack of knowledge in React, that has made it difficult to do a proof of concept.
July 4, 2019 at 8:26am
I suggest to check some tutorials on react / redux. In the case for the current jsonforms-react-seed you can achieve your goal with
1) Declaring what type of value you want to have in your application
export interface AppProps extends WithStyles<typeof styles> {dataAsString: string;hasErrors: boolean;}
2) Map the value from the state into the props
const mapStateToProps = (state: JsonFormsState) => {return {dataAsString: JSON.stringify(getData(state), null, 2),hasErrors: hasErrors(state)};};const hasErrors = (state: JsonFormsState) => {if (state.jsonforms.core && state.jsonforms.core.errors) {return state.jsonforms.core.errors.length !== 0;}return false;};
3) Use the value in your button
class App extends React.Component<AppProps, any> {render() {const { classes, dataAsString, hasErrors } = this.props;return (<div>...<input type={'button'} value={'Clickable when form is valid'} disabled={hasErrors}/>
I hope this helps you get on track ;)