Skip to content
Open
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
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Here are a few customization options
- `->fullWidth()` Set to full width
- `->showRefresh()` Request the resources again
- `->showSubtitle()` Show the resource's subtitle
- `->searchWithinSubtitle()` Search for the term within the subtitle as well as the display value
- `->help('<b>Tip:</b> help text')` Set the help text

### All Options Demo
Expand Down
10 changes: 9 additions & 1 deletion resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ export default {
}

return this.available.filter((resource) => {
return resource.display.toLowerCase().includes(this.search.toLowerCase())
const term = this.search.toLowerCase(),
display = resource.display.toLowerCase(),
subtitle = resource.subtitle ? resource.subtitle.toLowerCase() : null;

if (this.field.searchWithinSubtitle && subtitle) {
return display.includes(term) || subtitle.includes(term);
}

return display.includes(term);
});
},
hasErrors: function() {
Expand Down
12 changes: 11 additions & 1 deletion src/AttachMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class AttachMany extends Field

public $showSubtitle = false;

public $searchWithinSubtitle = false;

public $showOnIndex = false;

public $showOnDetail = false;
Expand All @@ -57,7 +59,7 @@ public function __construct($name, $attribute = null, $resource = null)

// fetch the submitted values
$values = json_decode(request()->input($attribute), true);

// if $values is null make it an empty array instead
if (is_null($values)) {
$values = [];
Expand Down Expand Up @@ -106,6 +108,7 @@ public function resolve($resource, $attribute = null)
'showToolbar' => $this->showToolbar,
'showRefresh' => $this->showRefresh,
'showSubtitle' => $this->showSubtitle,
'searchWithinSubtitle' => $this->searchWithinSubtitle,
]);
}

Expand Down Expand Up @@ -177,6 +180,13 @@ public function showPreview($showPreview=true)
return $this;
}

public function searchWithinSubtitle($searchWithinSubtitle=true)
{
$this->searchWithinSubtitle = $searchWithinSubtitle;

return $this;
}

public function showRefresh($showRefresh=true)
{
$this->showRefresh = $showRefresh;
Expand Down