Pristine icon indicating copy to clipboard operation
Pristine copied to clipboard

Possible to globally set default messages for built-in validators?

Open elseloop opened this issue 5 years ago • 2 comments

Is it be possible to programmatically define a default message for one of the built-in validators, such as required? That is, rather than defaulting to This field is required, can that string be set globally, perhaps at initiation, to something else? (I know that I can do this though data-attributes, but adding a data-attribute to every input becomes tedious pretty quickly, and I'm not seeing an alternative in the docs.)

If this is not already possible, perhaps the config object passed to new Pristine() could also take an object of messages, with keys there defining each of the built-in validators' default messages?

let defaultConfig = {
    classTo: 'form-group',
    errorClass: 'has-danger',
    successClass: 'has-success',
    errorTextParent: 'form-group',
    errorTextTag: 'div',
    errorTextClass: 'text-help',
    messages: {
        required: '🙅  This field is required!',
        email: 'Give us your email!',
       {...}
    }
};

elseloop avatar Oct 07 '20 17:10 elseloop

@elseloop, there's a commit related to this in the feature/i18n branch. It'll be merged into master soon!

sha256 avatar Oct 10 '20 12:10 sha256

@sha256 any update on this item? I see the feature/il8n branch is still open but it looks like this feature may have been merged in but I don't see it in the docs.

misterhamm-bzs avatar Aug 04 '21 18:08 misterhamm-bzs