wireui / wireui

TallStack UI components
https://v1.wireui.dev
MIT License
1.37k stars 166 forks source link

x-phone multiple mask #802

Open Artessan opened 6 months ago

Artessan commented 6 months ago

Describe the bug x-phone component: when a multiple mask the array is handle as one string

To Reproduce

<div class="col-span-2 lg:col-span-1">
    <x-phone id="multiple-mask" label="{{__('Phone')}}" mask="['(+##) ### ## ## ##, ### ## ## ##']"
             wire:model="contactForm.phone"/>
</div>

produce: ['(+12) 345 67 89 12, 345 67 89 12']

Expected behavior (+12) 345 67 89 12

Dependencies

django-wong commented 6 months ago

Did you try ['(+12) 345 67 89 12', '345 67 89 12'] ?

Artessan commented 6 months ago

Hey, tested, the result is the same.

after checking some parts of the code I think the problem is this:

this is the render data on the div

wireui_inputs_maskable({isBlur:false,model:null,emitFormatted:false,mask:'[\'(+##) ### ## ## ##\', \'### ## ## ##\']',})

the mask is echoing as string and in

ts/utils/masker/index.ts

export const applyMask: ApplyMask = (mask, value, masked = true): string | null => {
  return Array.isArray(mask)
    ? dynamicMasker(mask, str(value), masked)
    : singleMasker(mask, str(value), masked)
}

before this The mask is never checked, parse or split as array; So the isArray method is always false using single mask