Releases: jungsoft/formup
1.7.0
1.6.2
1.6.1
1.6.0
π₯ Support for auto-transform on submit!
Formup now supports auto-transform on submit! You can use any kind of .transform
in any schema field, and if you pass transformOnSubmit
option to useFormup
it will automatically transform your form values according to your schema when you submit your form.
You can check all implementation details here.
Suppose you do have this schema:
const exampleSchema = createSchema({
uppercaseInput: yup
.string()
.required()
.transform((value) => `${(value || '').toUpperCase()}`)
.label('Uppercase string'),
});
The transform value in yup works internally, that is, it'll execute the transform
between all form validations, but your form values will always be non-transformed:
form.values = {
uppercaseInput: "foo",
};
If you pass transformOnSubmit
to useFormup
, when you submit you form this happens:
const onSubmit = (values) => {
console.log(values.uppercaseInput); // will print "FOO"!
};
1.5.4
1.5.3
1.5.2
π Bugfixes
- π Fixed a bug where
arrayHelpers
wasn't being injected into the child component ofFormArrayField
.
π Improvements
-
π New exports! Formup is now exporting the components returned by
useFormup
:- Form
- FormInput
- FormArrayField
- FormInputGroup
- FormInputGroupItem
This means you don't have to get these components from useFormup
- if you want to, you can simply import these components from @formup/core
. This helps a lot with prop dependency since you don't need to pass these components as props anymore!
// These are the same:
import { FormInput } from "@formup/core";
// --
import { useFormup } from "@formup/core";
const { FormInput } = useFormup();
1.5.0
π₯ Support for array fields!
Formup now supports array fields! You can check all implementation details here.
Suppose you have an array in your schema, be it a simple array of primitive or string types, or an array of objects.
import * as yup from 'yup';
const familyMemberSchema = yup.object().shape({
name: yup.string()
.required()
.label('Name'),
email: yup.string()
.email()
.label('Email'),
}, locale);
const schema = yup.object().shape({
// Array of strings
colors: yup.array()
.of(
yup
.string()
.required(),
),
// Array of objects
familyMembers: yup.array()
.of(familyMemberSchema),
});
You can now easily render these fields using FormArrayField
, which is exported by useFormup
:
const Example = () => {
const {
FormArrayField,
formikForm,
FormInput,
Form,
} = useFormup(schema);
return (
<Form formikForm={formikForm}>
{/* Render array of strings */}
<FormArrayField name="colors">
{(items, arrayHelpers) => (
<>
{items.map((item, index) => (
<div key={item.path}>
<FormInput name={item.path} />
<button
onClick={() => arrayHelpers.remove(index)}
type="button"
>
Remove item
</button>
</div>
))}
<button
onClick={() => arrayHelpers.push()}
type="button"
>
Add item
</button>
</>
)}
</FormArrayField>
{/* Render array of objects */}
<FormArrayField name="familyMembers">
{(items, arrayHelpers) => (
<>
{items.map((item, index) => (
<div key={item.path}>
<FormInput name={item.getPath('name')} />
<FormInput name={item.getPath('email')} />
<button
onClick={() => arrayHelpers.remove(index)}
type="button"
>
Remove family member
</button>
</div>
))}
<button
type="button"
onClick={() => arrayHelpers.push({
email: '[email protected]',
name: 'Foo bar',
})}
>
Add new family member
</button>
</>
)}
</FormArrayField>
</Form>
);
};
π Improvements
-
π
FormInput
component now validates if the field passed by "name" exists within the schema. -
π
FormInputGroup
component now validates if the field passed by "name" exists within the schema. -
π
yup
version was bumped to0.29.1
. -
π Removed unnecessary dependencies.
1.4.0
π₯ Automatic mapping of schema properties into FormInput
properties
Formup will now automatically map schema properties into FormInput
properties, in an attempt to make your schema a single-source-of-truth in your code.
Currently, it will map:
label
intolabel
andaria-label
properties
Note: You can override any mapped property by passing it directly to FormInput
.