Enable submit button when all input fields are valid in Hyperscript?

Johan

I'm playing around with htmx and hyperscript and I want the "submit button" (Add User) to be enabled when all required input fields are valid in a form. In this case, a non-empty name and a valid email address must have been defined.

<form hx-post="/example" hx-target="#table tbody" hx-swap="beforeend">
        <label class="control-label" for="nameInput">Name</label>
        <input id="nameInput" name="name" class="form-control" type="text" required placeholder="John Doe"/>
        
        <label class="control-label" for="emailInput">Email</label>
        <input id="emailInput" name="email" class="form-control" type="email" required placeholder="[email protected]"/>
        <button _="<what should I write here??>" class="btn btn-primary" disabled>Add User</button>
    </div>
</form>

What should I write instead of <what should I write here??> to make this happen?

1cg

Something like this should work:

<button _="on change from closest <form/>
             for elt in <[required]/>
               if the elt's value is empty
                 add @disabled then exit
               end
             end
             remove @disabled" class="btn btn-primary" disabled>Add User</button>

https://jsfiddle.net/xy8vn5jk/20/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Clear all input fields on submit using Hyperscript

Javascript - Enable Submit button when all input is valid

Enable submit button only when all fields are not empty - type > file & select & input

How to enable submit button when input fields are filled dynamically?

Enable submit button when the input fields are not empty and the checkbox checked

Enable submit button only when all fields are filled

jQuery Validate plugin, enable submit button when form is valid

How to enable submit button When I entered data in all input tags in the form

The simplest way to enable form submit button when text input is not empty

Disable submit button in React functional component if all input fields are not completed

jQuery enable Submit button only if all form fields has class before form submit

(Android) Enable button only when all login fields are not giving an error

Enable Submit Button After Form fields are fill

WPF command binding with input validation - how to enable the "save" button only if all input is valid

Enable Submit Button If All Checkboxes Are Checked

If all checkboxes are checked enable submit button

INPUT fields and SUBMIT button are not "disabled". Why?

disabling submit button till input fields are validated

Disable submit button until input fields are filled

Disabled submit button, but valid form data will not enable it (vee-validate)

Submit onBlur function only when the input is valid

Enable submit button when select checkbox

Submit button stops working in rails when using javascript to validate input fields when using form_tag

How to disable form submit button until all input fields are filled?! ReactJS ES2015

How to disable form submit button until all input fields are filled in ReactJS?

Disable submit button until all fields are complete

How can I use javascript to enable a "create account" button once all fields have correct input?

Check if all input fields are valid using js

Enable Button once all EditText Fields are not empty