react
react copied to clipboard
Validation for custom component
Hi,
I am working on to create a custom component in the form builder, I am able to validate the data on submission via checkValidity method but I need the submit button to be disabled if the form is invalid.
And right now the error message is showing up in alert box but I need that to show below the custom component.
Please help me to achieve proper validation for the custom component.
Current checkValidity function:
checkValidity(data, dirty) {
if (this.originalComponent.validate.required) {
if (!data.customComponent.agree) {
this.invalid = true;
this.error = 'This error message appears in alert box';
return false;
}
if (data.customComponent.agree && !data.customComponent.data) {
this.invalid = true;
this.error = 'This error message appears in alert box';
return false;
}
}
return true;
}