taiga-family/maskito

๐Ÿš€ - Options to get Raw/Original/Unmask value

hihahihahoho opened this issue ยท 4 comments

Which package(s) are relevant/related to the feature request?

No response

Description

for example if i input number: 100000, i will be able to get { value: 100,000, rawValue: 100000}

That would not be possible for any complex masking case, because original value can be changed tremendously. You get raw values in processors, but after everything is finished โ€” it's gone. Say your postprocessor changes all 'good' into 'bad'. Then you go and add a char in the middle to make it 'bard'. What would be the raw value? If you just want to have the unformated number, there's a utility function maskitoParseNumber mentioned in the docs at the very top:
https://maskito.dev/kit/number

I actually think this would be pretty useful - in some cases I need to format a postal code for user input with a separator, like "12-345" but the API I'm sending this value to expects a clean value, without the "12345". I understand that removing the mask after it is applied is impossible, but it seems feasible to just keep the unformatted value somewhere else.

I gave an example where there is no such thing as "unformatted" value generally speaking. You have a few options:

  1. unmask your values before sending them to the API.
  2. make a plugin to emit raw value for every input โ€” listen to beforeinput event in capture phase to make sure it kicks in before masking
  3. create a wrapper for storing your values that would mask and unmask automatically.
  4. create a plugin that will emit unmasked value automatically.

Here's an example using Angular directive as a wrapper:
https://stackblitz.com/edit/angular-4hcxec?file=src%2Fapp%2Funmask.directive.ts

EDIT: Here's an example using plugin:
https://stackblitz.com/edit/angular-4hcxec?file=src%2Fapp%2Funmask.plugin.ts