-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFR] Refactor validators to not return translated errors #3339
Conversation
I noticed that we don't handle errors and helperText the same way for all inputs. Some will display the error instead of the helperText, some will display both. I think it would be better to handle this in a consistant way by introducing an |
87baf9b
to
5e7fa46
Compare
5e7fa46
to
9b02c03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed first part
packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.js
Outdated
Show resolved
Hide resolved
}); | ||
|
||
describe('error message', () => { | ||
it('should not be displayed if field is pristine', () => { | ||
const { container } = render( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep this test
this.props.input.onBlur(value); | ||
this.setState({ value }); | ||
}; | ||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously a code smell. This is the implementation of the previous componentWillReceiveProps
. Hopefully this will not be needed after migrating to final-forms
Thanks! |
This is the first step to migrate from redux-form to
final-form
. Indeed,react-final-form
validators won't receive props anymore, so our current third argument containing thetranslate
function will always be empty.This PR refactor the validators to return either a string which will be translated or an object with
message
andargs
properties.I also introduced an unstyled
ValidationError
component which knows how to translate those errors. As it returns the resulting string inside a React Fragment, it can be defined inra-core
and used in any UI library.Finally, I updated the official inputs to use this
ValidationError
. In the process, I have migrated their tests fromenzyme
toreact-testing-library
and ensured all inputs support thehelperText
prop.ValidationError
componentInputHelperText
component