How do you change the mask pattern based on what's selected in another field dropdown menu, in angular-imask? #1067
Unanswered
gutierrezh2
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would use the
MaskedDynamic
and thedispatch
method used in the guide, however, I need to dynamically create the pattern itself based the dropdown options can also change.I'm using
angular-imask
, and have the following code:HTML:
<custom-dropdown-element
(ValueChange)=setMask(selectedItem)>
<input [imask]=getMask(currentInputValue) [unmask]='typed'"/>
Typescript:
private this.MaskUpdated;
SetMask(selectedItem) {
let newMask = IMask.createMask(maskPattern);
newMask.mask = newPattern;
newMask.updateOptions(newMask);
NewMask._rebuildMask();
This.MaskUpdated = newMask;
}
GetMask(currentValue) {
This.MaskUpdated.resolve (currentValue.toString());
Return this.maskUpdated;
}
The code above is really simplified, but it's basically the gist of it, but I can update if it's still not clear enough. Basically, for the [imask] input, I use a getter to pass the input's current value, resolve the value with the mask, then pass the mask with the resolved value.
As for the dropdown, based on what the user selects, the pattern mask changes. I cannot use the dispatch example as I cannot list all of the possible pattern masks available.
The code above only works when I change the input value; when the page is first loaded, the correct pattern doesn't show.
Any help would be appreciated, thanks!
Beta Was this translation helpful? Give feedback.
All reactions