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
48 changes: 48 additions & 0 deletions examples/empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Stimulus Autocomplete</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script async src="https://unpkg.com/es-module-shims@1.2.0/dist/es-module-shims.js"></script>
<script type="importmap-shim">
{
"imports": {
"@hotwired/stimulus": "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
}
}
</script>

<script type="module-shim">
import { Application } from '@hotwired/stimulus'
import { Autocomplete } from './stimulus-autocomplete.js'

const application = Application.start()
application.register('autocomplete', Autocomplete)
</script>

<style>
.container {
max-width: 600px;
}
</style>
</head>

<body>
<div class="container">
<h1 class="my-5">Stimulus autocomplete test</h1>

<div class="mb-3">
<label for="birds">Plain text bird names</label>
<div data-controller="autocomplete" data-autocomplete-url-value="/results-empty.html">
<input name="birds" type="text" class="form-control" data-autocomplete-target="input" placeholder="search a bird" autofocus/>
<input type="hidden" name="bird_id" data-autocomplete-target="hidden"/>
<ul data-autocomplete-target="results" class="list-group"></ul>
</div>
</div>
</div>
</body>
</html>
Empty file added examples/results-empty.html
Empty file.
2 changes: 1 addition & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class Autocomplete extends Controller {
replaceResults(html) {
this.resultsTarget.innerHTML = html
this.identifyOptions()
if (!!this.options) {
if (!!this.options && html) {
this.open()
} else {
this.close()
Expand Down