I perform my own checks in certain fields, so that only certain values ββare accepted (depending on the field), and the rest are rejected. I would like to write a filter function that checks which attribute is called validation, and from there decides which words are allowed to be used by the attribute. Thus, the model will look something like this:
module.exports = { types: { filter: function(attribute) { if (attribute === 'number') { switch(attribute.value) { case 'one': return true; case 'two': return true; default: return false; } } else if (attribute === 'color') { switch(attribute.value) { case 'red': return true; case 'blue': return true; default: return false; } } }, }, attributes: { number: { type: 'string', required: true, filter: true }, color: { type: 'string', required: true, filter: true } } };
Of course, in the usual Sails.js behavior, an β attribute β will not be an attribute, but an attribute value. (And attribute.value was just an example, I want the attribute value to be there).
So, I want attribute be the actual attribute that I called the validation rule. Is this possible with Sails? I mean, I could write a function for each field in the model, but it would be nice to have a function that suits them all (I have a lot of them).
Thanks.
Jamham
source share