Skip to content

Commit 32dd56e

Browse files
Update README.md
1 parent 49a2587 commit 32dd56e

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,18 @@ For example: you have id, code and parent_code. Your model uses id as key, but t
156156
->withKey('code')
157157
```
158158

159-
Store fetched models for additional functionality.
159+
Store fetched models for additional functionality
160160

161161
```PHP
162162
->storeResults()
163163
```
164164

165-
Now you can access the results in disabledOptions/hiddenOptions for custom functions like making only a branch node family selectable.
165+
Now you can access the results in `disabledOptions` or `hiddenOptions`
166166

167167
```PHP
168-
// Note: $component->getResults() is null in afterStateUpdated() as the tree is rebuilt
169-
->disabledOptions(function ($state, SelectTree $component) {
170-
if ($state) {
171-
$results = $component->getResults();
172-
$selectedNode = $results->firstWhere('id', $state[0]);
173-
$selectedFamily = $results->where('parent_id', $selectedNode?->parent_id)->pluck('id')->toArray();
174-
175-
while ($selectedNode?->parent_id) {
176-
$selectedFamily[] = $selectedNode?->parent_id;
177-
$selectedNode = $results->firstWhere('id', $selectedNode?->parent_id);
178-
}
179-
return $results->whereNotIn('id', $selectedFamily)->pluck('id')->toArray();
180-
}
181-
return [];
182-
})
168+
->disabledOptions(function ($state, SelectTree $component) {
169+
$results = $component->getResults();
170+
})
183171
```
184172

185173
## Filters

0 commit comments

Comments
 (0)