In one of my pages I have a select
element and a form
. What I want to achieve is to update the field values in the form when the select
changes, which happens successfully. I did many tests and read the documentation on htmx.org several times until I got this, but even now I don’t understand why my configuration works. Is it a bug? It is correct? I’m not sure at all, especially when I get the same good result with both hx-target="#title,#slug,#shortcode"
and hx-target="#shortcode"
, the main one being at least one of the three target ids to be included in the hx-target
, otherwise the select
is removed when the form fields are replaced. What do you think?
<select id="select-settings" name="select-settings" hx-get="/get-settings" hx-target="#title,#slug,#shortcode">
<option value="">-- Select Settings --</option>
<option value="super-opt10ns">Dolor qui voluptatem</option>
</select>
<form id="field-form" action="options.php" method="post">
<input type="text" id="title" name="title" value="">
<input type="text" id="slug" name="slug" value="">
<input type="text" id="shortcode" name="shortcode" value="">
</form>
Response from the /get-settings endpoint:
<input type="text" hx-swap-oob="outerHTML:#title" id="title" name="title" value="Dolor qui voluptatem">
<input type="text" hx-swap-oob="outerHTML:#slug" id="slug" name="slug" value="super-opt10ns">
<input type="text" hx-swap-oob="outerHTML:#shortcode" id="shortcode" name="shortcode" value="[form slug='test']">