@@ -49,6 +49,8 @@ class SelectTree extends Field
4949
5050 protected string $ direction = 'auto ' ;
5151
52+ protected array $ disabledOptions = [];
53+
5254 protected function setUp (): void
5355 {
5456 // Load the state from relationships using a callback function.
@@ -118,7 +120,7 @@ private function buildTreeFromResults($results, $parent = null): Collection
118120 // Group results by their parent IDs
119121 foreach ($ results as $ result ) {
120122 $ parentId = $ result ->{$ this ->getParentAttribute ()};
121- if (! isset ($ resultMap [$ parentId ])) {
123+ if (!isset ($ resultMap [$ parentId ])) {
122124 $ resultMap [$ parentId ] = [];
123125 }
124126 $ resultMap [$ parentId ][] = $ result ;
@@ -141,6 +143,7 @@ private function buildNode($result, $resultMap): array
141143 $ node = [
142144 'name ' => $ result ->{$ this ->getTitleAttribute ()},
143145 'value ' => $ result ->id ,
146+ 'disabled ' => in_array ($ result ->id , $ this ->getDisabledOptions ())
144147 ];
145148
146149 // Check if the result has children
@@ -251,6 +254,13 @@ public function independent(bool $independent = true): static
251254 return $ this ;
252255 }
253256
257+ public function disabledOptions (array $ disabledOptions = []): static
258+ {
259+ $ this ->disabledOptions = $ disabledOptions ;
260+
261+ return $ this ;
262+ }
263+
254264 public function alwaysOpen (bool $ alwaysOpen = true ): static
255265 {
256266 $ this ->alwaysOpen = $ alwaysOpen ;
@@ -324,4 +334,9 @@ public function getDirection(): string
324334 {
325335 return $ this ->evaluate ($ this ->direction );
326336 }
337+
338+ public function getDisabledOptions (): array
339+ {
340+ return $ this ->evaluate ($ this ->disabledOptions );
341+ }
327342}
0 commit comments