Skip to content

Commit

Permalink
Update Money.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sneycampos authored Aug 18, 2024
1 parent 6b852d5 commit 00d1c39
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ protected function setUp(): void
->prefix('R$')
->maxLength(13)
->extraAlpineAttributes([

'x-data' => '{ formatMoney(value) {
value = value.replace(/\D/g, "");
value = (parseFloat(value) / 100).toLocaleString("pt-BR", { minimumFractionDigits: 2 });
return value === "NaN" ? "0,00" : value;
}}',

'x-on:keypress' => 'function() {
var charCode = event.keyCode || event.which;
if (charCode < 48 || charCode > 57) {
event.preventDefault();
return false;
}
return true;
}',
var charCode = event.keyCode || event.which;
if (charCode < 48 || charCode > 57) {
event.preventDefault();
return false;
}
return true;
}',

'x-on:keyup' => 'function() {
var money = $el.value;
money = money.replace(/\D/g, \'\');
money = (parseFloat(money) / 100).toLocaleString(\'pt-BR\', { minimumFractionDigits: 2 });
$el.value = money === \'NaN\' ? \'0,00\' : money;
}',
$el.value = this.formatMoney($el.value);
}',

'x-init' => 'function () {
$el.value = this.formatMoney($el.value);
}'
])
->dehydrateMask()
->default(0.00)
Expand Down

0 comments on commit 00d1c39

Please sign in to comment.