nekodb
nekodb copied to clipboard
function to prevalidate before save
necessary to check if user possibly introduced wrong data type before de save
Can you elaborate or maybe give an example? There is a prevalidate hook as well as a presave hook though I'm not sure which you need without an example.
const TypeCheckModel = ko.Model('TypeCheck', {
field: ko.Number
})
TypeCheckModel.presave = function (model, next) {
if (typeof model.field !== 'number') {
return next(new Error('Invalid data type'))
}
next()
}
Is how you'd use a hook to perform this kind of validation, though I'm not sure why you wouldn't just use the schema itself to enforce type.