mobx-react-form
mobx-react-form copied to clipboard
Sync error messages (update localization)
Is there a way to mobx-react-form error messages with validator plugin error messages? I'm using DVR and when field is validated error message is shown. If I change my localization, error message won't update because Field has its error property already set. This is my current implementation:
class FieldBase extends Field {
constructor(props) {
super(props);
validatorService.on('onMessageSourceChange', async () => {
if (this.showError) {
await this.validate();
this.showErrors(!this.isValid);
}
});
}
@computed get localizedError() {
return _.replace(this.error, /\[(.*)\]/, function (match, value) {
return localizationService.t(value);
})
}
}
Problem is that I need to force validate field again to get new error messages. Language is changed when validatorjs.useLang('language');
is called and validatorjs has its new messages after that but I can't immediatelly update displayed error message because Field is not synced. This is not a big problem for now, but I'm going to have async validations which might be a problem to re-validate.
Is there a way to call something like syncPluginErrorMessages() where Field or Form would update its error message? If not, is there a change something like this could be added?
Thank you.
@zeljkohuber the maintainer of this lib hasn't really been active so I would maybe make your own fork if you need the functionality sooner rather than later. a lot of issues have "I'll look into this!" with no followup. I've been trying to maintain my own fork at https://github.com/Bidvine/mobx-react-form so if you want to make a PR against our fork, that would be cool
(there's still a lot to be done in our fork, too)