Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad Usability "ui-percentage-mask="2" + ui-negative-number" #334

Open
ivanguimam opened this issue Mar 26, 2018 · 2 comments
Open

Bad Usability "ui-percentage-mask="2" + ui-negative-number" #334

ivanguimam opened this issue Mar 26, 2018 · 2 comments

Comments

@ivanguimam
Copy link

Using the two directives together, when I focus on input and type the "-" sign before typing any number, it does not let me type any number. For both directives to work together, I need to enter the number first and only then put the minus sign, this to the user is horrible.

<input ng-model="$ctrl.coupon.value" required type="tel" class="form-control custom-input"
max="1" id="value" ui-percentage-mask="2" ui-negative-number ng-disabled="$ctrl.isUpdate">
@ivanguimam
Copy link
Author

Edit the parse function in the src/global/percentage/percentage.js file

...
var actualNumber = parseFloat(modelMask.apply(valueToFormat));

if (isNaN(actualNumber)) { // ADD THIS CONDITION TO FIX THE PROBLEM
    actualNumber = parseFloat(modelMask.apply(value.replace(/[^0-9]/g,'')))
    valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0'
    formatedValue = viewMask.apply(valueToFormat) + percentageSymbol;
}

if (angular.isDefined(attrs.uiNegativeNumber)) {
...

@lucasjorge944
Copy link

lucasjorge944 commented May 30, 2022

I created this fix directive, to apply with percentage directive and solved the problem for me.

angular.module("nucont").directive("fixInputMask", function () {
    return {
        restrict: "A",
        require: "ngModel",
        link: function (scope, element, attrs, ctrl) {
            element.on("keyup", function (ev) {
                scope.$apply(function () {
                    if (isNaN(ctrl.$modelValue)) {
                        const value = `-0,${Number(ev.key)}0`;

                        ctrl.$setViewValue(value);
                        ctrl.$render();
                    }
                });
            });
        }
    };
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants