unserver-unify
Version:
34 lines • 1.42 kB
JavaScript
;
angular.module('bamboo').directive('bbPwdValidate', function(pwdService, $translate) {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
// add a parser that will process each time the value is
// parsed into the model when the user updates it.
if (!element.attr('placeholder')) {
pwdService.getValidateRule().then(function(rule) {
element.attr('placeholder', $translate.instant(rule))
});
};
ctrl.$parsers.unshift(function(value) {
var valid;
if (value) {
pwdService.getValidateRegex().then(function(regex) {
valid = value.match(regex);
console.info(valid);
var res = valid ? true : false;
console.info(res);
ctrl.$setValidity('password', res);
//console.info(ctrl);
//return res ? value : undefined;
});
}
return value;
// if it's valid, return the value to the model,
// otherwise return undefined.
//return valid ? value : undefined;
});
}
}
});