Closed maxime-rainville closed 1 month ago
There appears to be a lot of specs for JSON Form schema:
Maybe we should look at picking one approach used by someone else instead of maintaining our own.
import { Form, Field } from 'react-final-form'
export function MyForm {
return <Form
onSubmit={onSubmit}
validate={validate}
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Field
name="bio"
render={({ input, meta }) => (
<div>
<label>Bio</label>
<textarea {...input} />
{meta.touched && meta.error && <span>{meta.error}</span>}
</div>
)}
/>
// ...
<FormBuilder>
to a functional componentimport { useState } from "react";
import { useForm } from "react-hook-form";
export function MyForm() {
const { register, handleSubmit } = useForm();
const [data, setData] = useState('');
return (
<form onSubmit={handleSubmit((data) => setData(JSON.stringify(data)))}>
<Header />
<input {...register("firstName")} placeholder="First name" />
// ...
<FormBuilder>
to a functional componentimport React from 'react';
import { useFormik } from 'formik';
export function MyForm() {
const formik = useFormik({
initialValues: objectOfData,
onSubmit: values => {
alert(JSON.stringify(values, null, 2));
},
});
return (
<form onSubmit={formik.handleSubmit}>
<label htmlFor="firstName">First Name</label>
<input
id="firstName"
type="text"
onChange={formik.handleChange}
value={formik.values.firstName}
/>
// ....
Spike complete and discussed. Next step is https://github.com/silverstripe/silverstripe-admin/issues/1747
Redux Form is no longer in active development.
The maintainer of Redux Form recommend migrating to React Final Form instead.
Redux form is used by our form schema abstraction.
Timebox
Objectives of the SPIKE
Note
This is really about rendering forms. If you can fine a library that comes with its own form schema standard, that would also be acceptable.