51 lines
1.5 KiB
JavaScript
Executable File
51 lines
1.5 KiB
JavaScript
Executable File
'use strict';
|
|
/**
|
|
* Password-check directive.
|
|
*/
|
|
app.directive('compareTo', function () {
|
|
return {
|
|
require: "ngModel",
|
|
scope: {
|
|
otherModelValue: "=compareTo"
|
|
},
|
|
link: function (scope, element, attributes, ngModel) {
|
|
|
|
ngModel.$validators.compareTo = function (modelValue) {
|
|
return modelValue == scope.otherModelValue;
|
|
};
|
|
|
|
scope.$watch("otherModelValue", function () {
|
|
ngModel.$validate();
|
|
});
|
|
}
|
|
};
|
|
});
|
|
app.directive('capitalize', function() {
|
|
return {
|
|
require: 'ngModel',
|
|
link: function(scope, element, attrs, modelCtrl) {
|
|
var capitalize = function(inputValue) {
|
|
if (inputValue == undefined) inputValue = '';
|
|
var capitalized = inputValue.toUpperCase();
|
|
if (capitalized !== inputValue) {
|
|
modelCtrl.$setViewValue(capitalized);
|
|
modelCtrl.$render();
|
|
}
|
|
return capitalized;
|
|
}
|
|
modelCtrl.$parsers.push(capitalize);
|
|
capitalize(scope[attrs.ngModel]); // capitalize initial value
|
|
}
|
|
};
|
|
});
|
|
app.directive('disallowSpaces', function() {
|
|
return {
|
|
restrict: 'A',
|
|
|
|
link: function($scope, $element) {
|
|
$element.bind('input', function() {
|
|
$(this).val($(this).val().replace(/ /g, ''));
|
|
});
|
|
}
|
|
};
|
|
}); |