Skip to content

Commit

Permalink
refactor the currency mask to use native alpine x-model
Browse files Browse the repository at this point in the history
  • Loading branch information
ariaieboy committed May 14, 2024
1 parent 8523166 commit dbc207b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions resources/views/currency-mask.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
$xdata = <<<JS
{
input:\$wire.{$applyStateBindingModifiers("\$entangle('{$statePath}')")},
masked:'',
init(){
\$el.value = this.input?.toString().replaceAll('.','$decimalSeparator');
this.masked = this.input?.toString().replaceAll('.','$decimalSeparator');
\$watch('masked',()=>this.updateInput());
\$watch('input',()=>this.updateMasked());
\$el.addEventListener('input',(event)=>this.updateInput());
\$el.addEventListener('blur',(event)=>this.updateInput());
},
updateMasked(){
if(typeof Number(this.input) === 'number'){
Expand Down Expand Up @@ -79,7 +79,7 @@ class="fi-fo-text-input"
'step' => $getStep(),
'type' => 'text',
'x-data' => $xdata,
'x-on:change'=>'updateInput',
'x-model'=>'masked',
'x-mask:dynamic' => $xmask
], escape: false)
"
Expand Down

0 comments on commit dbc207b

Please sign in to comment.