Skip to content
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

Sync error messages (update localization) #469

Open
zeljkohuber opened this issue Dec 18, 2018 · 1 comment
Open

Sync error messages (update localization) #469

zeljkohuber opened this issue Dec 18, 2018 · 1 comment

Comments

@zeljkohuber
Copy link

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.

@Dakkers

This comment was marked as spam.

@foxhound87 foxhound87 changed the title Sync error messages Sync error messages (update localization) Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants