You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why is this FR worth it?
First: Countries dictionary appears to be able to filter countries by subregions, but this has not be fully implemented yet
Second: there are many similar cases that could be handled by creating a custom dictionary based on this countries dictionary
countries and states (or regions, or landers...)
states and counties (or smaller administrative regions within a big region)
counties and cities
cities and districts
and so on
Thinking for example of a city picker that allows for choosing a district where a specific service could be proposed.
1_ Create a relationship between regions and their subregions
One subregion is related to one region only: I am thinking of something like that (?)
'africa' => ['africa', 'subregion' => $this->subregions['central_africa', 'eastern_africa', 'northern_africa', 'southern_africa', 'south_eastern_africa']],
'europe' => ['europe', 'subregion' => $this->subregions ['eastern_europe', 'northern_europe', 'southern_europe', 'western_europe']]
And so on.
2_Add the subregions in the field items:
2.1
protected function fieldItems()
{
return [
'region' => [
'display' => __('Region'),
'instructions' => __('statamic::messages.dictionaries_countries_region_instructions'),
'type' => 'select',
'options' => $this->regions,
],
'subregion' => [
'display' => 'Subregion',
'instructions' => 'Filter regions by subregions.',
'type' => 'select',
'options' => $this->subregions,
],
];
}
2.2
CRITICAL: Restrict available values of subregions only to the ones related to the regions selected.
Currently, you can add 2.1 above in the Countries dictionary, it's working but ALL subregions are available whatever the region you select first.
3_Unselecting region or subregion
Provide a solution to easily unselect either a subregion or a region. Those fields are optional but somehow you cannot unselect your choice and must choose another Dictionary type to erase everything. Cumbersome.
4_Improve function getFilteredItems(): Collection
4.1 Add a test for the subregion:
->when($this->config['subregion'] ?? false, fn ($collection, $subregion) => $collection->where('subregion', $this->subregions[$subregion]));
4.2 But when a subregion isn't selected, the function should check for the region. What I wrote below isn't working but this is just a hint a what I would like to achieve:
->when(($this->config['region'] ?? false) and ($this->config['subregion'] === false ), fn ($collection, $region) => $collection->where('region', $this->regions[$region]));
The text was updated successfully, but these errors were encountered:
Why is this FR worth it?
First: Countries dictionary appears to be able to filter countries by subregions, but this has not be fully implemented yet
Second: there are many similar cases that could be handled by creating a custom dictionary based on this countries dictionary
and so on
Thinking for example of a city picker that allows for choosing a district where a specific service could be proposed.
1_ Create a relationship between regions and their subregions
One subregion is related to one region only: I am thinking of something like that (?)
'africa' => ['africa', 'subregion' => $this->subregions['central_africa', 'eastern_africa', 'northern_africa', 'southern_africa', 'south_eastern_africa']],
'europe' => ['europe', 'subregion' => $this->subregions ['eastern_europe', 'northern_europe', 'southern_europe', 'western_europe']]
And so on.
2_Add the subregions in the field items:
2.1
protected function fieldItems()
{
return [
'region' => [
'display' => __('Region'),
'instructions' => __('statamic::messages.dictionaries_countries_region_instructions'),
'type' => 'select',
'options' => $this->regions,
],
'subregion' => [
'display' => 'Subregion',
'instructions' => 'Filter regions by subregions.',
'type' => 'select',
'options' => $this->subregions,
],
];
}
2.2
CRITICAL: Restrict available values of subregions only to the ones related to the regions selected.
Currently, you can add 2.1 above in the Countries dictionary, it's working but ALL subregions are available whatever the region you select first.
3_Unselecting region or subregion
Provide a solution to easily unselect either a subregion or a region. Those fields are optional but somehow you cannot unselect your choice and must choose another Dictionary type to erase everything. Cumbersome.
4_Improve function getFilteredItems(): Collection
4.1 Add a test for the subregion:
->when($this->config['subregion'] ?? false, fn ($collection, $subregion) => $collection->where('subregion', $this->subregions[$subregion]));
4.2 But when a subregion isn't selected, the function should check for the region. What I wrote below isn't working but this is just a hint a what I would like to achieve:
->when(($this->config['region'] ?? false) and ($this->config['subregion'] === false ), fn ($collection, $region) => $collection->where('region', $this->regions[$region]));
The text was updated successfully, but these errors were encountered: