Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ability to transform value before write #841

Closed
dev054 opened this issue Dec 11, 2020 · 1 comment
Closed

Provide ability to transform value before write #841

dev054 opened this issue Dec 11, 2020 · 1 comment

Comments

@dev054
Copy link

dev054 commented Dec 11, 2020

🚀 feature request

There are some cases where we should allow only letters (say full name) and as the user types, we transform to uppercase.

Describe the solution you'd like

I'd like to have an option to transform value before masking.

<!-- the name could be any, it's just an idea ->
<input matInput formControlName="test" mask="S*" [transformer]="transformerFn">
transformerFn = (value: string) => value.toLocaleUppercase();

this.formGroup.get('test').valueChanges.subscribe(console.log); // fired only once, with the value uppercased

Describe alternatives you've considered

Well, while we could add a directive to perform its transformation by listening input event, but has the following drawback:

  • The valueChanges/(change) would be emitted twice. One for the value masked and another for the value uppercased. To try workaround this you could setValue passing { emitEvent: false }, however it would be a problem, because you'll have an outdated value in valueChanges/(change);
andriikamaldinov1 added a commit that referenced this issue Aug 15, 2023
NepipenkoIgor pushed a commit that referenced this issue Aug 18, 2023
* fix(#841): fix(#841)

* fix(#890): fix(#890)

* fix(#890): fix(#890)

* fix(#890): fix(#890)

* fix(#890): fix(#890)

* fix(#890): fix(#890)

* fix(#890): fix(#890)

* fix(#890): fix(#890)
@andriikamaldinov1
Copy link
Collaborator

@dev054 Thanks for using Ngx-mask. We add two new function "inputTransformFn" and "outputTransformFn".
It example with your case - https://stackblitz.com/edit/stackblitz-starters-wj3nvw?file=src%2Fmain.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants