TextField Validation Bug
Environment Information
- Package version(s): latest
Please provide a reproduction of the bug in a codepen:
Actual behavior:
This if statement looks wrong to me....

Shouldn't be:
if (validateOnFocusIn || validateOnFocusOut) {
this._delayedValidate(newProps.value);
}
When validateOnFocusIn or validateOnFocusOut is true, validation is not triggered.
Also when validateOnFocus is false, it validates... That should not be...
Expected behavior:
Should trigger validation
Priorities and help requested:
Are you willing to submit a PR to fix? (Yes, No)
Requested priority: (Blocking, High, Normal, Low)
Products/sites affected: (if applicable)
I just recently noticed this too while working on #8723, and definitely agree that its purpose is not clear at a glance! From reading the code, I think the idea is that if validateOnFocusIn or validateOnFocusOut is provided, the TextField should only validate on those events. Otherwise, the TextField should validate on any change.
In #8723 I'm adding a named helper function to encapsulate that check and make it a bit clearer what's going on:
function _validateOnAnyChange(props: ITextFieldProps): boolean {
// If one of these props is true, we should validate **only** on focus in and/or out.
// Otherwise, we should validate on any change.
return !(props.validateOnFocusIn || props.validateOnFocusOut);
}
Does that make sense?
Not sure I understand that logic.
So if validateOnFocusIn is true, it will not validate onChange?
I have a scenario where this is not working for me. When validateOnFocusIn or Out is false, the field validates when I change the value of my state. It should not validate, but when I set validateOnFocusIn to true, it does not validate when I change the state, which is what I want but that just doesn't make sense.
I took the time to create a Code Pen to show you the bug.
https://codepen.io/paradimeweb/pen/PgeLOQ
validateOnFocusIn/Out means validate only on those events, and don't validate on change. (Those props were apparently added in response to #692, in case you're curious about the history.) I just made #8793 to make that explicit in the documentation. I also thought about changing the prop names, but I can't think of better names that aren't ridiculously long.
This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React!