I have a question regarding validation of inputs. I'm using Fabric UI for the textfields, which have onGetErrorMessage, which I'm using to validate input. The textfield is a controlled element. It is all working well, except one moment, when I do a reset / clear of the fields, it triggers the validation and then I get error messages, saying cannot be empty, which is fine due to the validation, but not fine if we are talking about reset.
I'll post here parts of the code which I use.
const els: React.ReactElement[] = [];
els.push(<ChoiceGroup label = "Choice" selectedKey = {student.Choice} options = {choices} onChange = {(e: any, selectedItem: any) => ...} />);
els.push(<TextField label='Name' required value = {student.Name} onChange = {(e: any, value: any) => ....} validateOnLoad = {false}
onGetErrorMessage = {(value: string) => validate('Name', value, els)} />);
els.push(<TextField key='Age' label="Age" required value = {student.Age} onChange = {(e: any, value: any) => ..} validateOnLoad = {false}
onGetErrorMessage = {(value: string) => validate('Age', value, els)} />);
We have 3 elements, which are shown, now on choice change, I need to clear the textfields, which I do as follows:
useEffect(() => {
// I modify the state here, and set Age and Name of the student object to ''
// which triggers then onGetErrorMessage
}, [student.Choice]);
What is the best way to reset values of the textfields, without triggering validate, but this still has to work when user manually clears textfield (making it empty)
Any idea? I would appreciate .... been stuck with it for some time...