CodeWithDennis / filament-select-tree

The multi-level select field lets you pick one or multiple options from a list that is neatly organized into different levels.
MIT License
225 stars 33 forks source link

[Feature Request]: Hide specific option from the tree #40

Closed ivanBell199 closed 11 months ago

ivanBell199 commented 11 months ago

Thank you for this package, it's great! I wanted to use it in my "Category" form to select the parent category. It's working very well, but I have one issue. When editing a category, it is included in the select tree. Of course, a category cannot be parent to itself. Is it possible to hide it from the tree or make it unclickable? Or maybe you would consider adding this feature to the package. Thanks again.

CodeWithDennis commented 11 months ago

I'm happy you like the package! To fix the problem you mentioned, you can try using ->enableBranchNode(false) or simply remove the method from the tree.

SelectTree::make('categories')
   ->relationship('categories', 'name', 'parent_id')
   ->enableBranchNode(false),
Scherm­afbeelding 2023-11-15 om 22 12 25
ivanBell199 commented 11 months ago

Thanks for such a quick reply! It seems I wasn't clear enough in my explanation. I have CategoryResource in my Filament project. Let's say I create category "Electronics" and then inside it "PCs". Then I go to the Edit page for "PCs". There I have the tree of categories in case I need to reassign parent. As you can see, "PCs" is present in this tree: image Of course, it should be obvious that you can't set "PCs" as parent for itself. But for the sake of better UX I think it would be good to disable this option or remove from the tree. Unfortunately, I don't have enough coding skill to achieve that. So if you can give me a hint how to solve my problem, I will be very grateful :)

CodeWithDennis commented 11 months ago

This is not currently supported. However, I'll check the possibility of implementing something similar to the following:

->hideOptions([3,5,7])
->disableOptions([3,5,7])
ivanBell199 commented 11 months ago

Sounds great, thank you!

CodeWithDennis commented 11 months ago

Sounds great, thank you!

I just dropped version v3.1.9, and now you can disable options.

example-disable-options
ivanBell199 commented 11 months ago

Works nicely! Thank you for your work!

buzkall commented 11 months ago

I've done PR https://github.com/CodeWithDennis/filament-select-tree/pull/55 to add the code to hide options

->hideOptions([id])