forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchpreview-add-target-and-fill-in.diff
37 lines (35 loc) · 1.43 KB
/
searchpreview-add-target-and-fill-in.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff --git a/assets/controllers/search-preview_controller.js b/assets/controllers/search-preview_controller.js
index 7a74b35..a298f09 100644
--- a/assets/controllers/search-preview_controller.js
+++ b/assets/controllers/search-preview_controller.js
@@ -5,6 +5,8 @@ export default class extends Controller {
url: String,
}
+ static targets = ['result'];
+
async onSearchInput(event) {
const params = new URLSearchParams({
q: event.currentTarget.value,
@@ -12,6 +14,6 @@ export default class extends Controller {
});
const response = await fetch(`${this.urlValue}?${params.toString()}`);
- console.log(await response.text());
+ this.resultTarget.innerHTML = await response.text();
}
}
diff --git a/templates/product/index.html.twig b/templates/product/index.html.twig
index 3d5a68f..c3cf015 100644
--- a/templates/product/index.html.twig
+++ b/templates/product/index.html.twig
@@ -50,6 +50,11 @@
class="form-control"
data-action="search-preview#onSearchInput"
>
+
+ <div
+ class="search-preview"
+ data-search-preview-target="result"
+ ></div>
</div>
</form>
</div>