Skip to content

Commit

Permalink
fix #1007
Browse files Browse the repository at this point in the history
  • Loading branch information
uNmAnNeR committed Mar 2, 2024
1 parent 2329dab commit 08b68c3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
23 changes: 13 additions & 10 deletions packages/imask/example.html
Expand Up @@ -12,22 +12,25 @@ <h1>IMask Core Demo</h1>
<!-- <script src="https://unpkg.com/imask"></script> -->
<script type="text/javascript">
const opts = {
mask: 'HH:MM',
mask: 'VLv\\alue MM',
lazy: false, // make placeholder always visible

blocks: {
HH: {
mask: IMask.MaskedRange,
from: 0,
to: 23,
maxLength: 2,
YY: {
mask: '00',
},

VL: {
mask: IMask.MaskedEnum,
enum: ['TV', 'HD', 'VR'],
},

MM: {
mask: IMask.MaskedRange,
from: 0,
to: 59,
maxLength: 2,
from: 1,
to: 12,
},
},
autofix: 'pad',
};

const input = document.getElementById('input');
Expand Down
6 changes: 5 additions & 1 deletion packages/imask/src/masked/enum.ts
Expand Up @@ -79,7 +79,7 @@ class MaskedEnum extends MaskedPattern {
return d;
}

return new ChangeDetails();
return new ChangeDetails({ skip: !this.isComplete });
}

override extractTail (fromPos: number=0, toPos: number=this.displayValue.length): TailDetails {
Expand All @@ -103,6 +103,10 @@ class MaskedEnum extends MaskedPattern {

return details;
}

override get isComplete (): boolean {
return this.enum.indexOf(this.value) >= 0;
}
}


Expand Down
17 changes: 17 additions & 0 deletions packages/imask/test/masked/enum.ts
Expand Up @@ -70,4 +70,21 @@ describe('MaskedEnum', function () {

assert.equal(masked.value, 'aaa');
});

it('should skip char if does not match', function () {
const enum_ = ['aaa', 'bbb', 'ccc'];
const masked = new MaskedEnum({ enum: enum_ });
const d = masked.append('x', { input: true, raw: true });

assert.equal(d.skip, true);
});

it('should not skip char if complete', function () {
const enum_ = ['aaa', 'bbb', 'ccc'];
const masked = new MaskedEnum({ enum: enum_ });
masked.value = 'aaa';
const d = masked.append('x', { input: true, raw: true });

assert.equal(d.skip, false);
});
});

0 comments on commit 08b68c3

Please sign in to comment.