-
Notifications
You must be signed in to change notification settings - Fork 16
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
Make messages live-updateable and maybe separate the validation and message creation in ember-cp-validations #24
Comments
That really depends on what you're validating and if what you're validating is dependent on the locale. So, I would say perhaps making it an option to revalidate on a dependent key change versus recomputing a message needs to be decoupled. Perhaps something like: validator('date-range', {
dependentKeys: ['startDate', 'endDate'],
messageDependentKeys: ['i18n.locale'] // we can do this internally for ember-i18n-cp-validations
}); In any case, I think changes on both ends would be needed to support this
This isn't a public API, so expectations should be limited on how you think it should behave versus what it was intended to solve.
Unsure what you mean by this.
I'm not sure I understand this either. |
Do you mean like for example for phone numbers, where you want to allow local numbers depending on the locale? Well my suggestion wouldn't break this, because this is existing functionality. But for most validators this is not required.
Thats exactly my suggestion. I think it should be public API.
Well, with my current solution (the snippet above) doing
will no longer produce the same as
which would be desirable.
Assume we have a Now we would like to have translations like this:
Now this doesn't work with my simple initializer above because the error object has not the required information to decide which message to print. However this can be returned by the validator. So instead of returning the message, we could return the options/validatorResult required by the
However this can be implemented in userland. You just can't use the built-in validators then. The important thing we need in I hope I was able to explain it a bit what I mean. |
I'll likely need time to investigate this further, but I'm not against the general idea of exposing an API for messages to be recomputed versus the entire validator. The implementation is just something we will need to coordinate with @offirgolan @offirgolan what are your thoughts? |
I think the reasoning here is pretty solid, it's just that being able to support something like this might be a bit tough. Tbh, I'm still having trouble wrapping my head around how exactly you guys want this to look like. @luxferresum can you give an example of what sort of API you expect / what you want the end goal to look like? |
I've just had some time to dig into this deeper. Later I will publish a WIP-PR on To be honest in my personal opinion the and goal would be a breaking change: specifying the validationsI think the existing API is pretty good here. Lets make a shot example with a simple
the validatorCurrently I could build a validator like this:
But better I do it like this:
However this has the problem that the error message is calculated during the validation process, and the
We could change the default implementation of
Now I would propose that the user can just create an file
If the user doesnt override the |
Hello
Yesterday I've talked with @offirgolan about that on slack and he recommended me to open an issue here so we can discuss this.
My Issue was that when I change the locale, the translated validation messages don't change. The recommended solution is to make the locale as an dependency of the validators, however this seems not an ideal solution, and is not practical at all when a validator makes an AJAX request.
The following
instance-inistializer
is a solution that works for me, but it has some caveats:The biggest problem is that the
descriptionKey
is not available. Also its a big ugly that the owner is not injected into theValidationError
. This forces me to use aninstance-initializer
instead of aninitializer
.Also
messages
andmessage
is not longer useful for me.Also I think it would be awesome to have a clean and documented way of doing what I want to do.
My thought was that we could look up the
ValidationError
class from the DI container, create an instance for each error and then fill it will all information about the failed validation:type
field
value
validationResult
which is currently themessage
options
passed to thevalidator
. Here we can look up thedescriptionKey
and so on.Next the
message
could be just a computed property because computed properties are awesome. This would be our implementation for compatibility with the current implementation:However the user could always override this by implementing
app/validations/error.js
and doing something like this:Next we would change
messages
to be a CP as well:In the next step we could think about shifting the validators from returning a human-readable error to returning a machine-readable error that we can use in the
ValidationError
for formatting and internationalization. However this would be a change of public APIs.What do you guys think about this approach?
The text was updated successfully, but these errors were encountered: