Skip to content

Commit

Permalink
fix #983
Browse files Browse the repository at this point in the history
  • Loading branch information
uNmAnNeR committed Dec 22, 2023
1 parent 802ad97 commit 4af0274
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
39 changes: 3 additions & 36 deletions packages/imask/example.html
Expand Up @@ -11,44 +11,11 @@ <h1>IMask Core Demo</h1>
<script src="dist/imask.js"></script>
<!-- <script src="https://unpkg.com/imask"></script> -->
<script type="text/javascript">
const numberOpts = {
mask: Number,
thousandsSeparator: ' ',
scale: 2,
radix: '.',
min: 0,
const opts = {
mask: Date,
autofix: 'pad',
};

class CurrencyMaskedDynamic extends IMask.MaskedDynamic {
get typedValue () {
return Number(this.unmaskedValue);
}

set typedValue (typedValue) {
this.unmaskedValue = String(typedValue);
}
}

const opts = new CurrencyMaskedDynamic({
mask: [
{
mask: '',
},
{
mask: '$num',
blocks: {
num: numberOpts,
}
},
{
mask: '{-}$num',
blocks: {
num: numberOpts,
}
}
],
});

const input = document.getElementById('input');
var result = document.getElementById('value');
var unmasked = document.getElementById('unmasked');
Expand Down
5 changes: 4 additions & 1 deletion packages/imask/src/masked/range.ts
Expand Up @@ -85,7 +85,10 @@ class MaskedRange extends MaskedPattern {
let details: ChangeDetails;
[ch, details] = super.doPrepareChar(ch.replace(/\D/g, ''), flags);

if (!this.autofix || !ch) return [ch, details];
if (!this.autofix || !ch) {
details.skip = !this.isComplete;
return [ch, details];
}

const fromStr = String(this.from).padStart(this.maxLength, '0');
const toStr = String(this.to).padStart(this.maxLength, '0');
Expand Down
18 changes: 18 additions & 0 deletions packages/imask/test/masked/pattern/insert.ts
Expand Up @@ -269,5 +269,23 @@ describe('Insert', function () {
masked.rawInputValue = '55';
assert.equal(masked.value, '5-5');
});

it('should not skip char for incomplete range block', function () {
masked.updateOptions({
mask: 'num-num',
blocks: {
num: {
mask: MaskedRange,
from: 0,
to: 10,
},
},
lazy: true,
overwrite: false,
});

masked.rawInputValue = 'aaaa';
assert.equal(masked.value, '');
});
});
});

0 comments on commit 4af0274

Please sign in to comment.