jonsamwell/angular-auto-validate

Overriding messages

Closed this issue · 6 comments

Love the work you're doing with this...

I would love to override the 'pattern' message as it's not that user-friendly. I can't expect my users to understand the constraints of a regex! :)

Anyways, I have not been successful doing this as per the docs here. Could you please provide a pointer or a little help getting this working? I assume the custom error message resolver is the way to go? Is this necessary for overriding just 1 message?

Hi,

Glad you like the module!!!

I've tried the code from the docs and it appears to work fine? What reference where you looking at?

This appears to work and you are right you don't need a custom error message resolver for this :-)

app.run([
            'defaultErrorMessageResolver',
            function (defaultErrorMessageResolver) {
                defaultErrorMessageResolver.getErrorMessages().then(function (errorMessages) {
                    errorMessages['pattern'] = 'Custom Error Message {0}';
                });
            }
        ]);

I've just created a quick plunker to test this http://plnkr.co/edit/CMxAVV6dVCFRsbHDKtgh?p=preview
I thought perhaps you are using an older version of the library as I had to change the API for this when I added i18n support so it was asynchronous and therefore had to be based around promises.

Let me know if you are still having trouble :-)

I've just updated my original blog post with the new api to avoid confusion.

Thanks! Appreciate the help!

No worries! Thanks for using the module :-)

This works for overwriting the error message for an input with 1 type of pattern, but usually my forms have multiple inputs with regex pattern attributes and I would like user-friendly error messages for each of them. Is there any way to get this to work?
Examples:
Phone Number:
Soc Security Number:
Zip Code:
Account Number: