Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Placeholder for original property name in message? #314

Open
jlem opened this issue Dec 22, 2019 · 0 comments
Open

Placeholder for original property name in message? #314

jlem opened this issue Dec 22, 2019 · 0 comments

Comments

@jlem
Copy link

jlem commented Dec 22, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant