Skip to content
Draft
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
10 changes: 7 additions & 3 deletions resources/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ document.addEventListener('livewire:init', () => {
},

escape($dispatch) {
if (!this.allowNew && this.autoSelect) this.resetValue($dispatch)
if (!this.allowNew && this.autoSelect) this.clearItem($dispatch)

this.hide()
},
Expand Down Expand Up @@ -254,9 +254,13 @@ document.addEventListener('livewire:init', () => {
},

setSelected($dispatch, selected) {
this.decoupledValue = null
const newValue = typeof selected === 'object' && selected.hasOwnProperty(this.searchAttribute) ? selected[this.searchAttribute] : selected
if (newValue === this.value) {
return
}

this.value = typeof selected === 'object' && selected.hasOwnProperty(this.searchAttribute) ? selected[this.searchAttribute] : selected
this.decoupledValue = null
this.value = newValue
this.selected = typeof selected === 'object' && selected.hasOwnProperty(this.idAttribute) ? selected[this.idAttribute] : selected
$dispatch((this.name ?? 'autocomplete') + '-selected-object', selected)
$dispatch((this.name ?? 'autocomplete') + '-selected', this.selected)
Expand Down
2 changes: 2 additions & 0 deletions resources/views/autocomplete.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

$autoSelect = filter_var($getOption('auto-select'), FILTER_VALIDATE_BOOLEAN);
$allowNew = filter_var($getOption('allow-new'), FILTER_VALIDATE_BOOLEAN);
$allowSelectionEdition = filter_var($getOption('allow-selection-edition'), FILTER_VALIDATE_BOOLEAN);
$loadOnceOnFocus = filter_var($getOption('load-once-on-focus'), FILTER_VALIDATE_BOOLEAN);
$inline = filter_var($getOption('inline'), FILTER_VALIDATE_BOOLEAN);
@endphp
Expand All @@ -29,6 +30,7 @@
searchAttribute: '{{ $getOption('text') }}',
autoSelect: {{ $autoSelect ? 'true' : 'false' }},
allowNew: {{ $allowNew ? 'true' : 'false' }},
allowSelectionEdition: {{ $allowSelectionEdition ? 'true' : 'false' }},
loadOnceOnFocus: {{ $loadOnceOnFocus ? 'true' : 'false' }},
})"
x-init="init($dispatch)"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
autocomplete="off"
{{ $attributes->class('w-full pl-4 py-2 rounded border border-cool-gray-200 shadow-inner leading-5 text-cool-gray-900 placeholder-cool-gray-400 focus:outline-none focus:border-blue-400 disabled:bg-cool-gray-100') }}
x-bind:class="[selected ? 'pr-9' : 'pr-4']"
x-bind:disabled="selected" />
x-bind:disabled="selected && !allowSelectionEdition" />