Skip to content

Commit

Permalink
Add selectable prop to new option form builder
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed May 23, 2022
1 parent ea0889b commit f51ab4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
21 changes: 13 additions & 8 deletions docs/src/form-fields/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Select::make()
->options(
Options::make([
Option::make('key', 'value'),
Option::make('key', 'value', selectable: false),
...
])
);
Expand Down Expand Up @@ -91,11 +92,8 @@ Select item option

Example of `selectable` prop usage:
```php
@formField('select', [
'name' => 'office',
'label' => 'Office',
'placeholder' => 'Select an office',
'options' => [
@php
$selectOptions = [
[
'value' => 1,
'label' => 'New York'
Expand All @@ -106,11 +104,18 @@ Example of `selectable` prop usage:
],
[
'value' => 3,
'label' => 'Berlin',
'label' => 'Berlin'
'selectable' => false // This item will be non-selectable in the select form component
]
]
])
];
@endphp

<x-twill::select
name="office"
label="office"
placeholder="Select an office"
:options="$selectOptions"
/>
```

A migration to save a `select` field would be:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@area17/twill",
"version": "2.8.0",
"version": "3.0.0",
"private": true,
"scripts": {
"inspect": "vue-cli-service inspect --mode production",
Expand Down
6 changes: 4 additions & 2 deletions src/Services/Forms/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ class Option implements Arrayable
public function __construct(
protected string|int $value,
protected string $label,
protected bool $selectable = true,
) {
}

public static function make(string|int $value, string $label): self
public static function make(string|int $value, string $label, bool $selectable = true): self
{
return new self($value, $label);
return new self($value, $label, $selectable);
}

public function toArray(): array
{
return [
'value' => $this->value,
'label' => $this->label,
'selectable' => $this->selectable,
];
}
}

0 comments on commit f51ab4a

Please sign in to comment.