adopted-ember-addons / ember-inputmask

Ember wrapper around Inputmask.js
https://adopted-ember-addons.github.io/ember-inputmask/
MIT License
68 stars 45 forks source link

Pasting a value with decimal=false results in the radix being removed, but not the decimal portion #17

Open jdhines opened 8 years ago

jdhines commented 8 years ago

I had a number-input with decimal=false and though that does prevent a user from entering a decimal point, if the user instead pastes in a value like 100.32, the decimal point is just removed, leaving 10032, which is obviously way bigger. The expected behavior is that the decimal portion be trimmed off.

It works fine, however, if decimals are allowed and the user pastes in a number with more decimal digits. For example, if they paste in 100.321, with default options, the input will show just 100.32.

I tried setting decimal=0 but that didn't fix it. I'm happy to submit a PR, but I don't know what to change to allow this. I'm guessing an else condition here, but I'm not sure:

//ember-inputmask/components/input-mask
...
updateMask: function() {
    this.setProperties({
      'options.autoGroup':      this.get('group'),
      'options.groupSeparator': this.get('separator'),
      'options.radixPoint':     this.get('radix'),
      'options.groupSize':      this.get('groupSize')
    });

    if (this.get('decimal') === true) {
      this.set('mask', 'decimal');
      this.set('options.digits', 2);
    } else if (this.get('decimal')) {
      this.set('mask', 'decimal');
      this.set('options.digits', this.get('decimal'));
    }

    this._super();
  }.observes('mask', 'group', 'decimal', 'separator', 'radix', 'groupSize')
brandynbennett commented 5 years ago

This seems to work for now.