Skip to content

Commit 9347f8e

Browse files
authored
Document new filter scopes (button-group & dropdown) (#235)
Documents wintercms/winter@4fe88d7
1 parent 3233963 commit 9347f8e

File tree

1 file changed

+108
-36
lines changed

1 file changed

+108
-36
lines changed

backend/lists.md

Lines changed: 108 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -595,35 +595,52 @@ These types can be used to determine how the filter scope should be displayed.
595595

596596
<div class="columned-list">
597597

598-
- [Group](#group-scope)
598+
- [Button Group](#button-group-scope)
599599
- [Checkbox](#checkbox-scope)
600-
- [Switch](#switch-scope)
601600
- [Date](#date-scope)
602601
- [Date range](#date-range-scope)
602+
- [Dropdown](#dropdown-scope)
603+
- [Group](#group-scope)
603604
- [Number](#number-scope)
604605
- [Number range](#number-range-scope)
606+
- [Switch](#switch-scope)
605607
- [Text](#text-scope)
606608

607609
</div>
608610

609-
### Group scope
611+
### Button Group scope
610612

611-
`group` - filters the list by a group of items, usually by a related model and requires a `nameFrom` or `options` definition. Eg: Status name as open, closed, etc.
613+
`button-group` – displays a row of buttons where only one option may be selected at a time. Ideal for small, mutually exclusive option sets (e.g., status filters like All / Active / Archived).
612614

613615
```yaml
614616
status:
615617
label: Status
616-
type: group
617-
conditions: status in (:filtered)
618-
default:
619-
pending: Pending
618+
type: button-group
619+
default: active
620+
conditions: status = :filtered
621+
options:
622+
all: All
620623
active: Active
624+
archived: Archived
625+
```
626+
627+
If a button is clicked again while it is already selected, it will deselect unless required: true is specified:
628+
629+
```yaml
630+
status:
631+
label: Status
632+
type: button-group
633+
required: true
634+
default: active
635+
conditions: status = :filtered
621636
options:
622-
pending: Pending
623637
active: Active
638+
pending: Pending
624639
closed: Closed
625640
```
626641

642+
Supports dynamic options using a method name or `modelClass` with `nameFrom`, same as [`group`](#group-scope).
643+
627644
### Checkbox scope
628645

629646
`checkbox` - used as a binary checkbox to apply a predefined condition or query to the list, either on or off. Use 0 for off and 1 for on for default value
@@ -636,42 +653,42 @@ published:
636653
conditions: is_published <> true
637654
```
638655

639-
### Switch scope
640-
641-
`switch` - used as a switch to toggle between two predefined conditions or queries to the list, either indeterminate, on or off. Use 0 for off, 1 for indeterminate and 2 for on for default value
656+
### Dropdown scope
642657

643-
Using conditions:
658+
`dropdown` - displays a compact single-select dropdown menu. Ideal for filtering by a single value from a short or medium-sized list, with an optional placeholder-like entry when no value is selected.
644659

645660
```yaml
646-
approved:
647-
label: Approved
648-
type: switch
649-
default: 1
650-
conditions:
651-
- is_approved <> true
652-
- is_approved = true
661+
status:
662+
type: dropdown
663+
emptyOption: Select status
664+
default: active
665+
conditions: status = :filtered
666+
options:
667+
all: All
668+
active: Active
669+
archived: Archived
653670
```
654671

655-
Using a scope method:
672+
You can also populate options dynamically:
656673

657674
```yaml
658-
approved:
659-
label: Approved
660-
type: switch
661-
default: 0
662-
scope: isApproved
675+
country:
676+
type: dropdown
677+
emptyOption: Select country
678+
modelClass: Winter\Test\Models\Location
679+
nameFrom: name
680+
conditions: country_id = :filtered
663681
```
664682

665-
```php
666-
public function scopeIsApproved($query, $state)
667-
{
668-
return match ($state) {
669-
'0' => $query,
670-
'1' => $query->where('is_approved', false),
671-
'2' => $query->where('is_approved', true),
672-
}
673-
}
674-
```
683+
Supported options:
684+
685+
- `emptyOption`: The placeholder text for an unselected state (acts like a "none" or prompt).
686+
- `default`: The default selected value.
687+
- `options`: Static array or method name on modelClass for dynamic options.
688+
- `modelClass` + `nameFrom`: Dynamically populate options from a model.
689+
- `required`: (optional) Prevents deselecting the current value.
690+
691+
> **NOTE:** When `required: true` is set, the `emptyOption` will be ignored. If no `default` is specified, the first available option will be automatically selected.
675692

676693
### Date scope
677694

@@ -750,6 +767,24 @@ published_at:
750767

751768
> **NOTE:** the `ignoreTimezone` option also applies to the `date` filter type as well.
752769

770+
### Group scope
771+
772+
`group` - filters the list by a group of items, usually by a related model and requires a `nameFrom` or `options` definition. Eg: Status name as open, closed, etc.
773+
774+
```yaml
775+
status:
776+
label: Status
777+
type: group
778+
conditions: status in (:filtered)
779+
default:
780+
pending: Pending
781+
active: Active
782+
options:
783+
pending: Pending
784+
active: Active
785+
closed: Closed
786+
```
787+
753788
### Number scope
754789

755790
`number` - displays input for a single number to be entered. The value is available to be used in the conditions property as `:filtered`.
@@ -788,6 +823,43 @@ visitors:
788823
conditions: visitors >= ':min' and visitors <= ':max'
789824
```
790825

826+
### Switch scope
827+
828+
`switch` - used as a switch to toggle between two predefined conditions or queries to the list, either indeterminate, on or off. Use 0 for off, 1 for indeterminate and 2 for on for default value
829+
830+
Using conditions:
831+
832+
```yaml
833+
approved:
834+
label: Approved
835+
type: switch
836+
default: 1
837+
conditions:
838+
- is_approved <> true
839+
- is_approved = true
840+
```
841+
842+
Using a scope method:
843+
844+
```yaml
845+
approved:
846+
label: Approved
847+
type: switch
848+
default: 0
849+
scope: isApproved
850+
```
851+
852+
```php
853+
public function scopeIsApproved($query, $state)
854+
{
855+
return match ($state) {
856+
'0' => $query,
857+
'1' => $query->where('is_approved', false),
858+
'2' => $query->where('is_approved', true),
859+
}
860+
}
861+
```
862+
791863
### Text scope
792864

793865
`text` - display text input for a string to be entered. You can specify a `size` attribute that will be injected in the input size attribute (default: 10).

0 commit comments

Comments
 (0)