Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ SelectTree::make('category_id')

// Ensures that only leaf nodes can be selected while preventing the selection of groups.
->disabledBranchNode()

// Adjust the emptyLabel for when there are zero search results.
->emptyLabel(__('No results found'))

// Show the count of children alongside the group's name.
->withCount()
Expand Down
2 changes: 1 addition & 1 deletion resources/dist/tree.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions resources/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function tree({
clearable = true,
isIndependentNodes = true,
alwaysOpen = false,
emptyText
}) {
return {
state,
Expand All @@ -39,6 +40,7 @@ export default function tree({
clearable,
isIndependentNodes,
alwaysOpen,
emptyText
});

this.tree.srcElement.addEventListener('input', (e) => {
Expand Down
1 change: 1 addition & 0 deletions resources/views/select-tree.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
showTags: '{{ $getMultiple() }}',
alwaysOpen: '{{ $getAlwaysOpen() }}',
clearable: '{{ $getClearable() }}',
emptyText: '{{ $getEmptyLabel() }}'
})"
>
<div x-ref="tree"></div>
Expand Down
14 changes: 14 additions & 0 deletions src/SelectTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SelectTree extends Field

protected bool $alwaysOpen = false;

protected string $emptyLabel;

protected bool $independent = true;

protected bool $clearable = true;
Expand Down Expand Up @@ -53,6 +55,13 @@ public function clearable(bool $clearable = true): static
return $this;
}

public function emptyLabel(string $emptyLabel): static
{
$this->emptyLabel = $emptyLabel;

return $this;
}

public function independent(bool $independent = true): static
{
$this->independent = $independent;
Expand Down Expand Up @@ -128,6 +137,11 @@ public function getDisabledBranchNode(): bool
return $this->evaluate($this->disabledBranchNode);
}

public function getEmptyLabel(): string
{
return $this->evaluate($this->emptyLabel);
}

public function tree(string $treeModel, string $treeParentKey, string $titleAttribute, Closure $modifyQueryUsing = null): static
{
$this->treeModel = $treeModel;
Expand Down