0.2.5 • Published 3 months ago
@xvii/useform v0.2.5
@xvii/useForm
Forms for ReactJS.
Installation
npm install --save @xvii/useform
Example
import { useForm } from '@xvii/useform';
const form = useForm({
onSubmit(formData) {
console.log("Submit", formData);
},
fields: {
login: {
valueType: String(),
validators: [
notEmpty({ errorText: "Login cannot be empty" }),
minLength({
errorText: "The login must be longer than 3 characters.",
minLength: 3,
}),
],
validateOnChange: true
},
password: {
defaultValue: "",
validators: [notEmpty({ errorText: "Password cannot be empty" })],
},
remember: {
defaultValue: false,
valueType: Boolean(),
},
},
});
<TextField
label="Login"
error={form.fields.login?.error}
helperText={form.fields.login?.errorText}
onChange={form.fields.login?.handleChange}
value={form.fields.login?.value}
/>
<Checkbox
checked={form.fields.remember?.value}
onChange={form.fields.remember?.toggle}
/>
Form
Property | Type | Description |
---|---|---|
fields | FormField | List of form fields |
getFormData | () => data | Returns an object with values of all fields |
handleSubmit | () => boolean | Handler function for submitting the form |
isValid | boolean | The current validity status of all fields |
setFormData | (data) => void | Sets the values of the form fields |
validate | () => void | Force validation of all fields |
FormField
Property | Type | Description |
---|---|---|
error | boolean | Validation error state |
errorText | string | Description of error |
handleChange | (evt) => void | Handler for onChange |
pushToArray | (value) => void | Add value for arrayable fields |
removeFromArray | (value) => void | Remove value from arrayable fields |
replaceValidators | () => void | Replace validators for current field |
setValue | (value) => void | Set value of field |
toggle | () => void | Toggler for boolean values |
validate | () => void | Force validation of field |
value | Value of field |
0.2.5
3 months ago
0.1.29
3 months ago
0.2.1
3 months ago
0.2.0
3 months ago
0.2.3
3 months ago
0.2.2
3 months ago
0.2.4
3 months ago
0.1.27
4 months ago
0.1.28
4 months ago
0.1.26
4 months ago
0.1.20
9 months ago
0.1.21
8 months ago
0.1.22
8 months ago
0.1.23
8 months ago
0.1.24
6 months ago
0.1.16
10 months ago
0.1.17
9 months ago
0.1.18
9 months ago
0.1.19
9 months ago
0.1.10
1 year ago
0.1.11
12 months ago
0.1.12
12 months ago
0.1.13
12 months ago
0.1.14
12 months ago
0.1.15
11 months ago
0.1.8
1 year ago
0.1.9
1 year ago
0.1.7
1 year ago
0.1.6
1 year ago
0.1.5
1 year ago
0.1.4
1 year ago
0.1.3
1 year ago
0.1.2
1 year ago
0.1.1
1 year ago
0.1.0
1 year ago