-
Notifications
You must be signed in to change notification settings - Fork 397
Java script error while validating numericality: greater_than with other model attribute #679
Copy link
Copy link
Closed
Labels
Milestone
Description
I have 2 attributes in my model - minimum_players and maximum_players. And i want compare them in validation:
validates :maximum_players, presence: true, numericality: { only_integer: true, greater_than: :minimum_players }
validates :minimum_players, presence: true, numericality: { only_integer: true, less_than: :maximum_players }The thing is, if in my form i'll erase the value, i'll get an error -
VM9416:3 Uncaught SyntaxError: Unexpected token }
at new Function (<anonymous>)
at Object.numericality (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:57073:18)
at executeValidators (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:56808:30)
at validateElement (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:56833:9)
at jQuery.fn.init.$.fn.isValid (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:56750:14)
at HTMLInputElement.<anonymous> (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:57884:40)
at HTMLInputElement.dispatch (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:5227:27)
at HTMLInputElement.elemData.handle (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:4879:28)
at Object.trigger (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:5131:12)
at Object.simulate (http://localhost:3000/assets/application-bb85fcb8fe8ac097e6f76a98bc2fa968ac9dc1d5a76c575d837a260aa4181540.js:5485:16)
So, i was wondering if adding the null-check on line 369
if (check_value) {
fn = new Function("return " + val + " " + operator + " " + check_value);
if (!fn()) {
return options.messages[check];
}
}like that can be done to fix that behaviour?
Reactions are currently unavailable