Last active
November 4, 2023 21:21
-
-
Save sjardim/ad65961826c31c2af6210317ed541158 to your computer and use it in GitHub Desktop.
Creating a Money custom field for Laravel Filament
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<x-dynamic-component | |
:component="$getFieldWrapperView()" | |
:id="$getId()" | |
:label="$getLabel()" | |
:label-sr-only="$isLabelHidden()" | |
:helper-text="$getHelperText()" | |
:hint="$getHint()" | |
:hint-action="$getHintAction()" | |
:hint-color="$getHintColor()" | |
:hint-icon="$getHintIcon()" | |
:required="$isRequired()" | |
:state-path="$getStatePath()" | |
> | |
{{--https://alpinejs.dev/plugins/mask--}} | |
<div class="filament-forms-text-input-component flex items-center space-x-2 rtl:space-x-reverse group" | |
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }"> | |
<span class="whitespace-nowrap group-focus-within:text-primary-500 text-gray-400"> | |
@if ($label = $getPrefixLabel()) | |
<span>{{ $label }}</span> | |
@endif | |
</span> | |
<div class="flex-1"> | |
<input {!! $isDisabled() ? 'disabled' : null !!} | |
class="block w-full transition duration-75 border-gray-300 rounded-lg shadow-sm focus:border-primary-500 focus:ring-1 focus:ring-inset focus:ring-primary-500 disabled:opacity-70 dark:bg-gray-700 dark:text-white dark:focus:border-primary-500 dark:border-gray-600" | |
wire:model.defer="{{ $getStatePath() }}" placeholder="0,00" type="text" | |
x-mask:dynamic="$money($input, ',')" /> | |
</div> | |
</div> | |
</x-dynamic-component> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Forms\Components; | |
use Filament\Forms\Components\Concerns\HasAffixes; | |
use Filament\Forms\Components\Field; | |
class Money extends Field | |
{ | |
use HasAffixes; | |
protected string $view = 'forms.components.money'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exatamente o que eu tava procurando! Não achei nenhuma forma de dividir o valor por 100 antes de enviar pro inputText, vou tentar implementar aqui e vlw @sjardim !
ps: acho que tem um ")" extra na linha 28 do arquivo "money.blade.php" fora isso a máscara parece ter funcionado como deveria. Será que tem uma mais parecida com a $.mask do falecido jQuery, que ao digitar 1 ele já preenche 0.01?