validaciones custom se bajan al cliente solo si son isExportable
This commit is contained in:
parent
a5df4afc0f
commit
9b76d3d004
|
@ -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);
|
||||
|
|
|
@ -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`);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue