validaciones custom se bajan al cliente solo si son isExportable

This commit is contained in:
Javi Gallego 2017-09-25 17:39:51 +02:00
parent a5df4afc0f
commit 9b76d3d004
6 changed files with 105 additions and 84 deletions

View File

@ -48,7 +48,7 @@ export function factory($translatePartialLoader, $http, $window, $ocLazyLoad, $q
switch (val.validation) {
case 'custom':
// TODO: Reemplazar eval
val.customValidator = eval(`(${val.customValidator})`);
val.bindedFunction = eval(`(${val.bindedFunction})`);
break;
case 'format':
val.with = new RegExp(val.with);

View File

@ -46,15 +46,7 @@ export const validators = {
throw new Error(`Invalid value`);
},
custom: function(value, conf) {
let valid = true;
function err(kind) {
valid = false;
}
let inst = {attr: value};
conf.customValidator.call(inst, err);
if (!valid)
if (!conf.bindedFunction(value))
throw new Error(`Invalid value`);
}
};

View File

@ -21,7 +21,7 @@ module.exports = function(self) {
count: true
};
for (let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
// this.disableRemoteMethod(method, disableMethods[method]);
}
};
@ -179,6 +179,15 @@ module.exports = function(self) {
});
};
};
self.validateBinded = function(propertyName, validatorFn, options) {
var customValidator = function(err) {
if (!validatorFn(this[propertyName])) err();
};
options.isExportable = true;
options.bindedFunction = validatorFn;
this.validate(propertyName, customValidator, options);
};
};
function removeEmpty(o) {
if (Array.isArray(o)) {

View File

@ -35,7 +35,9 @@ module.exports = function (server) {
for (let validation of validations[fieldName]) {
let options = validation.options;
if (options && options.async)
if ((options && options.async) ||
(validation.validation == 'custom' && !validation.isExportable))
continue;
jsonField.push(toJson(validation));

View File

@ -21,7 +21,7 @@ module.exports = function(self) {
count: true
};
for (let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
// this.disableRemoteMethod(method, disableMethods[method]);
}
};
@ -179,6 +179,15 @@ module.exports = function(self) {
});
};
};
self.validateBinded = function(propertyName, validatorFn, options) {
var customValidator = function(err) {
if (!validatorFn(this[propertyName])) err();
};
options.isExportable = true;
options.bindedFunction = validatorFn;
this.validate(propertyName, customValidator, options);
};
};
function removeEmpty(o) {
if (Array.isArray(o)) {

View File

@ -21,7 +21,7 @@ module.exports = function(self) {
count: true
};
for (let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
// this.disableRemoteMethod(method, disableMethods[method]);
}
};
@ -179,6 +179,15 @@ module.exports = function(self) {
});
};
};
self.validateBinded = function(propertyName, validatorFn, options) {
var customValidator = function(err) {
if (!validatorFn(this[propertyName])) err();
};
options.isExportable = true;
options.bindedFunction = validatorFn;
this.validate(propertyName, customValidator, options);
};
};
function removeEmpty(o) {
if (Array.isArray(o)) {