formkit
Installation
npm install @xkit/formkit --save
yarn add @xkit/formkit
Usage
import React from 'react';
import { Form, FormControl, FormSubmit } from 'formkit';
function App() {
function handleSubmit(values, { setSubmitting }) {
setSubmitting(false);
}
return (
<Form initialValues={{ user: { name: 'test' } }} onSubmit={handleSubmit}>
<label>
user.name
<FormControl name="user.name" />
</label>
<FormSubmit />
</Form>
);
}
Multiple submit buttons
import React from 'react';
import { Form, FormControl, FormSubmit } from 'formkit';
function App() {
function handleSubmit(values, { setSubmitting, action }) {
console.log(action);
setSubmitting(false);
}
return (
<Form initialValues={{ user: { name: 'test' } }} onSubmit={handleSubmit}>
<label>
user.name
<FormControl name="user.name" />
</label>
<FormSubmit action="save" />
<FormSubmit action="submit" />
</Form>
);
}
Props
- values
- errors
- submitting
Methods
- getValue(name)
- setValue(name, value)
- getError(name)
- setError(name, error)
- setValues(values)
- setErrors(errors)
- handleChange(value, name)
- handleFocus(name)
- handleBlur(name)
- handleSubmit(action)
License
MIT