Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Limiting input number type to 2 decimals

$
0
0

Hi, I have an Ember number type, I am trying to limit its decimal values to be only 2 digits.

{{input type="number" id=p.ViolationTypeId value=p.PenaltyAssessed maxlength="5" scale="0.01" pattern="^\d+(\.\d{0,2})?" key-down=(action ‘allowOnly2Decimals’) focusOut=(action ‘saveTotalPenalty’ p model.id p.PenaltyAssessed)}}

        allowOnly2Decimals: function (e1, event) {
            var boxId = '#' + event.path[0].id;

            var t = e1.toString().split('.');

            if (t[1] != null) {
                if (t[1].length == 2) {
                    this.limitDecimal = e1;
                    $(boxId).val(this.limitDecimal);
                    //$(boxId).readyOnly = true;
                }

                if (t[1].length >= 2) {
                    $(boxId).val(this.limitDecimal);
                }
            }
        }
    }

I am trying to limit my Textbox to allow only 2 digits after decimal but now its allowing 3 numbers after decimal, how can I make this input type number to allow only 2 decimals, if there is any setting, I tried with scale property and format properties nothing worked.

And is there any way that I can do it without using jQuery Id selector explicitly that I am setting “$(boxId).val(this.limitDecimal);”

Any help please?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles