useInputs with object
When you use an object, the input is VALID by default if there is no validation attached to it.
Import
Import useInputs from aio-inputs package
Create your inputs
For example, you want the name, and gender of a user.
Call useInputs like this.
Notice that we extract also the form object from aio-inputs. Because we can't use map like array to render our inputs. We will use form.each() instead, or just destructure our inputs and render them. It is up to you
If you log myInputs, you'll see an object where first keys are name and gender. Those keys have these ready-to-use properties.
Now bind myInputs, to some input element.
- With form.each(), MORE DETAILS
- With destructuring
That is it. The value entered by the user will be stored in corresponding name | gender.value() located in myInputs.
Validity
To know if your form (all your inputs) is valid, use isValid property. Every input has also his own valid property
You can RESET or also get all VALUES by using the FORM OBJECT.
Object with validation
Let's add validation to one of those two inputs. name will have validation (minLength 3).
Now bind myInputs, to some input element. We will also display the error message if an input is touched and is not valid.
That is it. The value entered by the user will be stored in correspondingip.valuelocated in myInputs.
Validity
To know if your form (all your inputs) is valid, use isValid property. Every input has also his own valid property
You can RESET or also get all VALUES by using the FORM OBJECT.
INPUTS PROPERTIES like name, type and many others are available.
Same for VALIDATION PROPERTIES like min, max and many others.
Hit next to find out how to use form object with aio-inputs.