-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Unable to set a custom validation on two or more fields #158
Comments
@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 // 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 |
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 |
@billdami isn't that exactly what the |
@mikeu you know what you're absolutely right. :D When I was originally trying to use the |
Hi!, i can't make a customValidator that check two fields in the changeset. The current changeset is hidden from validator for any reason, or simply i don't find a way go get it?
I think my usercase isn't very strange, i have to date and time fields that needs to be coherent between them.
The text was updated successfully, but these errors were encountered: