I have a Backbone Model and am doing some validation when the setter is called. Instead of returning an error, I want to overwrite the value. How do I do this?
myObj = Backbone.Model.extend({
// Attributes
x: function() { },
y: function() { },
// Validation
validate: function(atr) {
// Checking for number
var numberRegex = /^\d+$/;
if(!numberRegex.test(atr.x)) // not number
atr.x = 'NA'; // Trying to set x to "NA"
}
});
Thanks!