-
|
Hi all, I have this I came up with this setup based on the dynamic mask from the docs, but the mask is not working as expected (see below GIF), the mask jumps from one mask to the other even with starting input HTML<div>
<input [imask]="imaskCoupon" [unmask]="true" />
</div>TypeScriptimaskCoupon = {
mask: [
{
lazy: false,
mask: '# 000 000 0',
placeholderChar: '\u2000',
definitions: {
'#': /^(012|123)/,
},
},
{
lazy: false,
mask: '000000000',
placeholderChar: '\u2000',
},
],
};Above Angular example is on StackBlitz as a starting point to help me out. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Answering my own question: I made it work with using imaskCoupon = {
mask: [
{
lazy: false,
mask: '000 000 000 0',
placeholderChar: '\u2000',
startsWith: '012',
},
{
lazy: false,
mask: '000 000 000 0',
placeholderChar: '\u2000',
startsWith: '123',
},
{
lazy: false,
mask: '0000000000',
placeholderChar: '\u2000',
startsWith: '',
},
],
dispatch: function (appended, dynamicMasked) {
const number = (dynamicMasked.value + appended).replace(/\D/g, '');
return dynamicMasked.compiledMasks.find(function (m) {
return number.indexOf(m.startsWith) === 0;
});
},
};Working StackBlitz with updated code. |
Beta Was this translation helpful? Give feedback.


Answering my own question: I made it work with using
dispatch, it will check for the entered value and use the correct mask.