0.3.1 • Published 7 months ago

@xvii/useform v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@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

PropertyTypeDescription
fieldsFormFieldList of form fields
getFormData() => dataReturns an object with values of all fields
handleSubmit() => booleanHandler function for submitting the form
isValidbooleanThe current validity status of all fields
setFormData(data) => voidSets the values of the form fields
validate() => voidForce validation of all fields

FormField

PropertyTypeDescription
errorbooleanValidation error state
errorTextstringDescription of error
handleChange(evt) => voidHandler for onChange
pushToArray(value) => voidAdd value for arrayable fields
removeFromArray(value) => voidRemove value from arrayable fields
replaceValidators() => voidReplace validators for current field
setValue(value) => voidSet value of field
toggle() => voidToggler for boolean values
validate() => voidForce validation of field
valueValue of field
0.3.0

7 months ago

0.3.1

7 months ago

0.2.6

7 months ago

0.2.5

1 year ago

0.1.29

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.4

1 year ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.26

1 year ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.8

2 years ago

0.1.9

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago