uNmAnNeR / imaskjs

vanilla javascript input mask
https://imask.js.org
MIT License
4.96k stars 258 forks source link

iMask options not updating when new options are a partial of the existing options #1073

Open JSMike opened 2 months ago

JSMike commented 2 months ago

Describe the bug

Logical bug in core library that prevents mask options from updating when new options are a partial of the existing options.

Use case: Formatted input with show/hide toggle

When wanting to show the values of an input field that are currently hidden by changing the imask blocks configuration, imask fails to update options because of current logic to only apply changes when the new option key/values all existed in the previous, this logic does not pick up when there are omissions.

The logical issue is in updateOptions which calls optionsIsChanged which assumes the options have changed only if they don't exist in the current mask. This doesn't account for if some of the options have been removed, and returns false when the options have changed.

To Reproduce

https://stackblitz.com/edit/stackblitz-starters-ex7edc?file=src%2Fmain.ts

Expected behavior

When new options are passed that are a partial of the previous options then only the new options should apply and any configuration that was removed should not persist.

Environment:

Additional context

Adding unique keys, or changing the structure of the object resolves the issue, but it is not clear that a change like this is required to apply a new mask.