Skip to content

Commit

Permalink
feat(select) modifica o campo options
Browse files Browse the repository at this point in the history
  • Loading branch information
irineujunior committed Feb 16, 2024
1 parent a019737 commit e12496b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
75 changes: 63 additions & 12 deletions docs/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@
<x-form.textarea name="message" label="Mensagem" required/>
</div>
<div class="mb-3">
<x-form.select name="select" label="Select" :values="['' => '-', 'One' => 'One', 'Two' => 'Two', 'Three' => 'Three']" hint="Selecione uma opção" required/>
@php
$options = [
[
'value' => '',
'label' => '-'
],
[
'value' => 1,
'label' => 'Item01'
],
[
'value' => 2,
'label' => 'Item02 (desabilitada)',
'disabled' => true
]
];
@endphp
<x-form.select name="select" label="Select" :options="$options" required/>
</div>
<div class="mb-3">
<x-form.radio name="radio[]" label="Radio Button" hint="Selecione uma opção" :values="['One' => 'One', 'Two' => 'Two', 'Three' => 'Three', 'Four' => 'Four']" required/>
Expand Down Expand Up @@ -85,28 +102,62 @@
## Select

@demo
@php
$options = [
[
'value' => '',
'label' => '-'
],
[
'value' => 1,
'label' => 'Item01'
],
[
'value' => 2,
'label' => 'Item02 (desabilitada)',
'disabled' => true
]
];
@endphp
<div class="mb-3">
<x-form.select name="select" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']"/>
<x-form.select name="select01" :options="$options"/>
</div>
<div class="mb-3">
<x-form.select label="select" name="select" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']" required/>
<x-form.select label="Cidade" name="select02" :options="$options" required/>
</div>
<div class="mb-3">
<x-form.select label="select" name="select" hint="Selecione uma opção" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']"/>
<x-form.select label="Cidade" name="select03" :options="$options" hint="Selecione uma opção"/>
</div>
@enddemo

@verbatim

```blade
<div class="mb-3">
<x-form.select name="select" :values="['' => '-', One' => 'One', 'Two' => 'Two', 'Three' => 'Three']"/>
</div>
<div class="mb-3">
<x-form.select label="select" name="select" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']" required/>
</div>
<div class="mb-3">
<x-form.select label="select" name="select" hint="Selecione uma opção" :values="['' => '-', 'One' => 'One','Two' => 'Two', 'Three' => 'Three']"/>
@php
$options = [
[
'value' => '',
'label' => '-'
],
[
'value' => 1,
'label' => 'Item01'
],
[
'value' => 2,
'label' => 'Item02 (desabilitada)',
'disabled' => true
]
];
@endphp
<div class="mb-3">
<x-form.select name="select01" :options="$options"/>
</div>
<div class="mb-3">
<x-form.select label="Cidade" name="select02" :options="$options" required/>
</div>
<div class="mb-3">
<x-form.select label="Cidade" name="select03" :options="$options" hint="Selecione uma opção"/>
</div>
```

Expand Down
11 changes: 5 additions & 6 deletions src/View/Components/Forms/Inputs/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
public string $name = '',
public string $label = '',
public string $hint = '',
public array $values = [],
public array $options = [],
) {
$this->uuid = '-' . str(serialize($this))
->pipe('md5')
Expand All @@ -38,11 +38,10 @@ public function render(): string|View
])
}}
>
<option value="">-</option>
@foreach($values as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
@foreach($options as $option)
<option value="{{ $option['value'] }}" @disabled(isset($option['disabled']))>{{ $option['label'] }}</option>
@endforeach
</select>
<x-form.error field="{{ $name }}"/>
<x-form.hint message="{{ $hint }}"/>
HTML;
Expand Down

0 comments on commit e12496b

Please sign in to comment.