Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try with on htmx:afterRequest reset() me

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading