V
V
Vladimir Kuts2017-01-10 23:12:20
JavaScript
Vladimir Kuts, 2017-01-10 23:12:20

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
});


there is an input line

<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 />


If I enter the phone number 9281234567 from the keyboard - everything is ok. Intuitively, after +7, we type the code, then the phone number
. ) 812 34 56, in the model I get 7928123456
What can I do so that the number is both dialed and inserted correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2017-01-11
@azrail_dev

Strange implementation of the mask. Perhaps it is worth using something not from jQuery? Like ng-mask? Well, in general, in general, you can try to hang another input, change :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question