Comments (4)
@billdami isn't that exactly what the changes
parameter in the example and twiddle above gives you?
from ember-changeset-validations.
@hugoruscitti did you make any progress on this issue? I am facing the problem right now, with two date fields that are collectively only valid if the first is earlier than the second. I've made some progress, by using the changes
and content
parameters passed into the custom validation routine. For example,
// validators/custom.js
export default function validateLessThanAttr(largerAttrName = '') {
return (key, newValue, oldValue, changes, content) => {
const largerValue = Ember.get(changes, largerAttrName) || Ember.get(content, largerAttrName);
return parseInt(newValue) < parseInt(largerValue) || `Must be less than ${largerValue}`;
}
}
Here's a twiddle showing it in action. If you leave the larger number at its default, or set it to something new, and then change the smaller number to be greater than or equal to that, a validation error will appear. The logic would be very similar for dates of course, but with parsing via moment first, or however else you are dealing with them.
There is still one main problem with it that I'd like to find a way to address: A validation error on the smaller number isn't cleared if the larger number is changed to make a valid combination.
For example, if larger
is 10 and smaller
is 15, then the validation error on smaller
will say "Must be less than 10". If I then change larger
to be 20, the error message will still be there, saying that smaller
has to be less than the old value of 10. (This is another example of #152.)
from ember-changeset-validations.
I've run into this as well, it seems like its currently not possible to have a custom validator whose rules are dependent on the current values of other properties in the changeset (that have NOT yet been applied to the target object).
It seems like maybe in addition to the content
param (which is the underlying target object), the validators should be receiving another param, the changeset
?
from ember-changeset-validations.
@mikeu you know what you're absolutely right. :D When I was originally trying to use the changes
object for this, I was incorrectly testing for a truthy value, when in my case I should be just seeing if the changes object contains the property, even if its false
.
from ember-changeset-validations.
Related Issues (20)
- Feature request - sequential validations HOT 8
- Feature request - add a tracked isValidating flag for properties with async validations HOT 1
- async validator is called multiple times with the same value HOT 2
- Date validator does not respect 'rawOutput' option HOT 2
- async validators can complete out of order HOT 4
- Documentation for rawOutput
- (Octane) skipValidate=true in helper does not work HOT 2
- (Octane) Documentation update suggestion: passing the validation instance HOT 1
- ember inspector silently polluting `changes`? HOT 1
- Button attribute not updating using classic components syntax HOT 1
- Access Service from validator class
- Freezed value in Input HOT 5
- Update to ember-validates v4 is breaking change HOT 2
- allowBlank doesn't work with validateFormat() HOT 1
- [Proposal] Use isEmpty for the date validator's allowBlank alike the other validators
- Use of `assign` has been deprecated
- [rfc]: Externalize schema validation HOT 4
- Strange behavior with an array of objects HOT 2
- Dependent field validation capability
- Docs pages are missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-changeset-validations.