TextField: onGetErrorMessage still triggering on form load
It appears the validation is still checked on form load. You can see this behavior by making _getErrorMessage check something like value.length < 1. The onBlur and onFocus work correctly once you have entered and removed text from the field, but my initial thoughts were that it would be a good option to have the _getErrorMessage function not get called until the onBlur or onFocus events were triggered. This would allow the users to at least attempt to satisfy the validation before being prompted that it wasn't met.
Is this just an issue with my code or are you all seeing the same behavior that I mentioned above?
We discussed the behavior as part of #692 and came to agreement that component mount and prop changes should still trigger the validation. Mainly to handle cases where form data is already present and we need to show validation errors without user's focus/blur on the TextField. I agree that there can be cases like the one you have mentioned where we don't need onLoad validation but to me it looks like these are two separate concerns:
- External triggers: onLoad/prop changes.
- Internal triggers: onChange, focus or blur.
Mixing these two may again bring out cases which are not completely satisfied with current implementation. We can provide another prop validateOnMount to handle case 1. but before we get into that, can we check if there are other ways to solve specific cases?
FWIW, value.length < 1 looks more of a required field and you may choose to use required = { true } prop and return empty error message if value.length < 1 in your onGetErrorMessage. For other custom validations, onGetErrorMessage will return actual errors.
Let us know if this works for you. Thanks,
I will attempt to fix my issue with the current implementation. Thank you for your reply.
FWIW, I ran into the same issue.
My preference would be to optimize for the common case of "don't show validation before the user has interacted with the component". By not having built in support for the common case, we're basically forcing all users of the components to work around the base behavior in their own way.