Skip to content

Commit

Permalink
feat(textarea) adiciona contador de caracteres
Browse files Browse the repository at this point in the history
  • Loading branch information
irineujunior committed Feb 20, 2024
1 parent df280af commit c479901
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<x-form.input name="name" label="Nome" required/>
</div>
<div class="mb-3">
<x-form.textarea name="message" label="Mensagem" required/>
<x-form.textarea name="message" label="Mensagem" maxlength=100 required/>
</div>
<div class="mb-3">
@php
Expand Down
39 changes: 23 additions & 16 deletions src/View/Components/Forms/Inputs/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@ public function __construct(
public function render(): string|View
{
return <<<'HTML'
@if($label)
<x-form.label for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])>
{{ str($label)->lower()->ucfirst() }}
</x-form.label>
@endif
<textarea wire:model="{{ $name }}" {{ $attributes->merge([
'id' => $name . $uuid,
'rows' => $rows,
])->class([
'form-control',
'is-invalid' => $errors->has($name),
])
}}
></textarea>
<x-form.error field="{{ $name }}"/>
<x-form.hint message="{{ $hint }}"/>
<div x-data="{ count: 0 }" x-init="count = $refs.fieldToCount.value.length">
@if($label)
<x-form.label for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])>
{{ str($label)->lower()->ucfirst() }}
@if($attributes->has('maxlength'))
<span class="form-label-description">
<span x-html="count"></span>/<span x-html="$refs.fieldToCount.maxLength"></span></span>
@endif
</x-form.label>
@endif
<textarea wire:model="{{ $name }}" {{ $attributes->merge([
'id' => $name . $uuid,
'rows' => $rows,
])->class([
'form-control',
'is-invalid' => $errors->has($name),
])
}}
x-ref="fieldToCount" x-on:keyup="count = $refs.fieldToCount.value.length"
></textarea>
<x-form.error field="{{ $name }}"/>
<x-form.hint message="{{ $hint }}"/>
</div>
HTML;
}
}

0 comments on commit c479901

Please sign in to comment.