-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
DisplayNameKey or Metadata requirement? #328
Comments
The above solution that @jsobell mentioned works for me. Sorry for the late response!
|
How about ValidationRules
.ensure('fname').displayKey('common.labels.firstName')
.required()
.minLength(3)
... Then we'd add a second argument to the message provider's getDisplayName(propertyName: string, displayKey: string = null) Thoughts? |
We could, although I suspect that displayName and displayKey are mutually exclusive, and if we're providing a hook to allow the dev to choose whether or not to translate then we might as well leave it as displayName. People will either use displayName in a format they can use for translation, or in common format as a non-translatable field. I can see a common situation being that people have a DisplayName of 'Surname', and in their mutation code they look up a translation, and if one doesn't exists they leave the string unchanged. |
right- that's what I was thinking I don't want to do This makes it impossible for My thinking was |
Does this matter? Can you think of a use-case where the user might need to know? If we really want to provide flexibility and support all possibilities, we should have a |
I think |
OK, I don't think it's a huge issue. Why not
:) |
I have almost the same issue. Having ValidationRules
.ensure('fname').displayName('First Name')
.on(target)
.getDisplayKey((propertyName, displayKey) => {
return displayKey || `common.customer-form.labels.${propertyName}`
}) |
Also I suggest |
And maybe having access to the object in |
Any update here? I've just created a |
@fabioluz we're definitely going to implement this- did the solution discussed here cover your need? |
Yeah, it did cover my need. My solution's code is a bit different the but result is the same. |
A situation came up last night where @mroseboom wanted the following code:
The display name is translated, but it's clearly not using the property name as a key, and it's standard to have messages looked up by a key, so should we have the same thing for the DisplayName?
It currently only performs translation if a property name is supplied, but displayName is left null:
https://github.com/aurelia/validation/blob/master/src/implementation/standard-validator.ts#L30
If we had a
.metadata('')
that allowed arbitrary data to be associated with the rule.property then I suppose people could leave the displayName blank and use that if they chose, and it would give lots of flexibility, but it's not very elegant.I considered
.displayNameKey()
in the same way we have amessageKey
, but messageKeys are centralised, whereas the displayNameKey is simply a function intercept for multilingual purposes.Perhaps the easiest thing is to simply say
The text was updated successfully, but these errors were encountered: