Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear all input fields on submit using Hyperscript

I'm playing around with htmx and hyperscript, and I want all input fields in the form below to be cleared on submit:

<form hx-post="/example" hx-target="#table tbody" hx-swap="beforeend"
      _="<what should I write here??>">
        <label class="control-label" for="firstNameInput">First Name</label>
        <input id="firstNameInput" name="firstName" class="form-control" type="text" required placeholder="John"/>
        
        <label class="control-label" for="lastNameInput">Last Name</label>
        <input id="lastNameInput" name="lastName" class="form-control" type="text" required placeholder="Doe"/>
        <button class="btn btn-primary">Add User</button>
    </div>
</form>

I've tried replacing <what should I write here??> with e.g. on submit put '' into <input/> and on submit put '' into <input[value]/> and lots of other combinations but I fail to get this work.

Q: How can I clear all input fields when the form is submitted?

like image 882
Johan Avatar asked Jun 15 '26 18:06

Johan


1 Answers

Try with on htmx:afterRequest reset() me


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!