@codecraftkit
Documentation
The FormField is used to create fields faster, it have to be used with formik and can take many types like select, radio, text, etc...
You can see all FormField Types here
This component is based on Formik Field
it can be imported from the core.
import { FormField } from "@codecraftkit/core";
or alone.
import FormField from "@codecraftkit/formfield";
To use this FormField, you will need to import Formik like this.
import { Form, Formik } from 'formik'
FormField has to be a children of Formik in order to use its context, here an example:
<FormikinitialValues={{subject:""}}onSubmit={(values) => onSubmit(values, 'subject')}>{() => (<Form><Grid gap={4}><FormFieldtype='text'name='subject'label='Subject'required/><Buttontype='submit'size='xs'colorScheme='green'justifySelf='flex-end'>Submit</Button></Grid></Form>)}</Formik>
If FormField is not inside Formik it won't work
Example using FormField type text
Remember that the prop name
has to match with its respective initial value, in this case subject
<FormikinitialValues={{subject:""}}onSubmit={(values) => onSubmit(values, 'subject')}>{() => (<Form><Grid gap={4}><FormFieldtype='text'name='subject'label='Subject'required/><Buttontype='submit'size='xs'colorScheme='green'justifySelf='flex-end'>Submit</Button></Grid></Form>)}</Formik>
The prop name
is required in every FormField type in order to work correctly
This props can be used with every FormField type
type
text
password
pin
date
number
textarea
phone
editor
select
radio
checkbox
file
image
datepicker
typeAHead
slider
switch
yes
text
The type of the input
name
String
yes
Name that the field will take and it will be use it by formik
label
String
no
Title of the input
noLabel
Boolean
no
Remove the label
required
Boolean
no
Place a red Asterisk
loading
Boolean
no
Show a loading animation
variant
outline
filled
flushed
unstyled
no
outline
Change the input variant
size
sm
md
lg
no
md
Change the input size
isDisabled
Boolean
no
To disable the input
placeholder
String
no
placeholder of the input
onInputChange
(value)=> void
no
Input onChange event handler