Answer the question
In order to leave comments, you need to log in
Mask problem?
There is a directive
app.directive('myMask', function($timeout, $rootScope) {
var directive = {
restrict: 'AEC',
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
var isWithAutoUnMask = true;
isWithAutoUnMask = !attrs.hasOwnProperty('withoutunmask');
var maskFF = attrs.myMask;
if (maskFF) {
$timeout(function() {
$(element).inputmask({
mask: maskFF,
autoUnmask: isWithAutoUnMask,
showMaskOnFocus: true,
placeholder: " ",
definitions: {
'*': {
validator: "[0-9]",
cardinality: 1,
casing: "lower",
placeholder: "_"
},
'd': {
validator: "[0-9]",
cardinality: 1,
casing: "lower",
placeholder: " "
}
}
}).on('keyup paste', function() {
if ($(element).inputmask("isComplete")) {
ngModelCtrl.$setValidity('isComplete', true)
} else {
ngModelCtrl.$setValidity('isComplete', false)
}
var clearValue = $(element).val()
ngModelCtrl.$setViewValue(clearValue);
ngModelCtrl.$render();
})
}, 10);
}
}
}
return directive
});
<input class="form-field" id="id_phone" ng-model="loginForm.loginPhone" my-mask="+7 (ddd) ddd dd dd" name="phone" placeholder="телефон" type="text" focus_onend />
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question