Skip to content

Commit

Permalink
Merge pull request #10 from ariaieboy/9-bug-dynamic-update-not-work-w…
Browse files Browse the repository at this point in the history
…ith-currencymask

9 bug dynamic update not work with currencymask
  • Loading branch information
ariaieboy authored Nov 21, 2023
2 parents 0a9032f + 38d74f0 commit 54a640b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions resources/views/currency-mask.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
$xdata = <<<JS
{
input:\$wire.{$applyStateBindingModifiers("\$entangle('{$statePath}')")},
masked:'',
init(){
this.masked = this.input?.toString().replaceAll('.','$decimalSeparator');
\$watch('masked',()=>this.updateInput());
\$watch('input',()=>this.updateMasked());
\$el.addEventListener('input',(event)=>updateInput());
\$el.addEventListener('blur',(event)=>updateInput());
},
updateMasked(){
if(typeof this.input === 'number'){
\$el.value = this.input?.toString().replaceAll('.','$decimalSeparator');
\$el.dispatchEvent(new Event('input'));
}
},
updateInput(){
this.input = this.masked?.replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.');
this.input = \$el.value?.replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.');
}
}
JS;
Expand Down Expand Up @@ -70,9 +77,9 @@ class="fi-fo-text-input"
'readonly' => $isReadOnly(),
'required' => $isRequired() && (! $isConcealed),
'step' => $getStep(),
'x-model' => 'masked',
'type' => 'text',
'x-data' => $xdata,
'x-on:change'=>'updateInput',
'x-mask:dynamic' => $xmask
], escape: false)
"
Expand Down

0 comments on commit 54a640b

Please sign in to comment.