My current code is:
<form id="search-form" hx-post="/search-api" hx-target="#search-result"></form>
<div class="search-wrapper">
<div class="material-icons search-button md-8 md-light" role="button" type="submit" form="search-form">search</div>
<div class="search-bar-wrapper">
<textarea name="search" type="text" class="search-bar" id="search-bar" form="search-form" placeholder="search" oninput="autoResize(this)"></textarea>
</div>
</div>
<div id="search-result"></div>
I can’t submit the form when I click the div, do I have to add some onclick="htmx.trigger(…)" like that? I can’t figure out how the htmx.trigger
function works though.
2
Answers
You can insert a hidden input field inside the div to help you access the containing form and submit.
You can create an event listener on the "button" and in the callback function call
submit()
on the form element.But why not just a standard form with a button and a input element for a search string like below?