Closed Firman95 closed 6 years ago
The problem is you didn't pass the function, instead you called the function directly:
return Validator.value(propertyName)
.required()
.custom(propNameExistValidation(propertyName,propUuid));
Should be changed to:
return Validator.value(propertyName)
.required()
.custom(propNameExistValidation);
But I can not pass parameter to the custom rule that way. This is what i do. In the custom rule, I return function, instead of validation result value:
import {Validator} from 'simple-vue-validator';
let propertyName,propertyUuid;
let fn = function () {
if (!Validator.isEmpty(propertyName)) {
return axios.post('/myApi', {
property_name: propertyName,
propertyUuid: propertyUuid
}).then((response) => {
let valid = (response.data.valid == 'true');
if (!valid) {
return Vue.i18n.translate('errors.propertyNameExist');
}
});
}
}
export default function propNameExistValidation(propertyName_,propertyUuid_) {
propertyName = propertyName_;
propertyUuid = propertyUuid_;
return fn;
};
And the validator stays the same:
return Validator.value(propertyName)
.required()
.custom(propNameExistValidation(propertyName,propUuid));
This is my validator
And this is my propNameExistValidation.js
EDIT: If i use function directly inside custom parameter, it works just fine.