You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currency = {
type: Number,
min: 0,
set: function(v) {
if (typeof v === 'string' && v.length > 1 && v[0] === '$') {
return parseFloat(v.substr(1)) * 100;
} else {
return v;
}
},
get: function(v) { // fails validatation when used
return '$' + (v / 100).toFixed(2);
}
};
var User = new Schema({
cash: Currency
});
var user = new User({cash: "$2.50"});
console.log(user.cash); // error
If getters are meant for display-only I don't think they should be subject to validation (especially since we're generating it, obviously we're going to be okay with the output)
The text was updated successfully, but these errors were encountered:
In addition this the setter doesn't work because it's never called ("$2.50" isn't a number, but I setters should be called first in case they can be converted into the proper format)
If getters are meant for display-only I don't think they should be subject to validation (especially since we're generating it, obviously we're going to be okay with the output)
The text was updated successfully, but these errors were encountered: