mirror of
https://github.com/tenrok/maska.git
synced 2026-05-15 11:59:38 +03:00
refactor!: change completed behavior for dynamic mask
This commit is contained in:
+13
-1
@@ -81,7 +81,7 @@ const options = reactive({
|
||||
</template>
|
||||
```
|
||||
|
||||
## Changed eager mode
|
||||
## Eager mode
|
||||
|
||||
With v2, when using eager mode, entered characters appeared after the static mask characters:
|
||||
|
||||
@@ -100,3 +100,15 @@ mask.masked('1') // -> 1
|
||||
mask.masked('12') // -> 12
|
||||
mask.masked('2') // -> 12
|
||||
```
|
||||
|
||||
## Completed behavior for dynamic masks
|
||||
|
||||
In v2 a dynamic mask is considered completed when it matches the longest mask in the array.
|
||||
For example, when you have enter `1-234`, but not `1-2`:
|
||||
|
||||
```html
|
||||
<input v-maska data-maska="['#-#', '#-###']">
|
||||
```
|
||||
|
||||
In v3 a dynamic mask is considered complete if it matches the first matched mask.
|
||||
So `1-2` and `1-234` are considered complete, but `1-23` is not.
|
||||
|
||||
+1
-3
@@ -78,11 +78,9 @@ export class Mask {
|
||||
|
||||
if (typeof this.opts.mask === 'string') {
|
||||
return length >= this.opts.mask.length
|
||||
} else if (typeof this.opts.mask === 'function') {
|
||||
return length >= mask.length
|
||||
}
|
||||
|
||||
return this.opts.mask.filter((m) => length >= m.length).length === this.opts.mask.length
|
||||
return length >= mask.length
|
||||
}
|
||||
|
||||
private findMask (value: string): string | null {
|
||||
|
||||
+4
-1
@@ -770,7 +770,10 @@ test('dynamic mask', () => {
|
||||
|
||||
expect(mask.unmasked('a123456789012345')).toBe('12345678901234')
|
||||
|
||||
expect(mask.completed('12345678901')).toBe(false)
|
||||
expect(mask.completed('1234567890')).toBe(false)
|
||||
expect(mask.completed('12345678901')).toBe(true)
|
||||
expect(mask.completed('123456789012')).toBe(false)
|
||||
expect(mask.completed('1234567890123')).toBe(false)
|
||||
expect(mask.completed('12345678901234')).toBe(true)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user