validate.js icon indicating copy to clipboard operation
validate.js copied to clipboard

Placeholder for original property name in message?

Open jlem opened this issue 6 years ago • 0 comments

The default validation messages attempt to turn the property name into something human readable, but this is not good if you're trying to provide specific information about a config property or something else that should tell the developer which property failed the validation.

I was wondering if there was a placeholder to get the original property name.

For example, if have this definition right now:

        const rules = {
            apiBaseUrl: {
                url: { 
                     message: `^- apiBaseUrl: Expected a URL, given %{value} instead.
                },
            },
            clientBaseUrl: {
                url: { 
                     message: `^- clientBaseUrl: Expected a URL, given %{value} instead.
                },
            }
        };

I should be able to generalize this message and assign it to the URL validator generically with a message like this:

"^%{property}: Expected a URL, given %{value} instead."

Where %{property} is the exact name of the property being validated, rather than a human readable version.

Is this possible in the current version, if not then I'd like to make this a feature request.

jlem avatar Dec 22 '19 20:12 jlem