silverstripe / silverstripe-admin

Silverstripe Admin Component
BSD 3-Clause "New" or "Revised" License
25 stars 91 forks source link

SPIKE Look at moving away from Redux Form for CMS 6 #1711

Closed maxime-rainville closed 1 month ago

maxime-rainville commented 3 months ago

Redux Form is no longer in active development.

image

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.

maxime-rainville commented 2 months 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.

emteknetnz commented 1 month ago

Recommendation:

Existing setup - FormSchema

Existing setup - redux form state management:

Existing setup - notable react components are:

Redux-form:

React-final-form:

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>
          )}
        />
// ...

React-hook-form:

import { 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" />
// ...

Formik

import 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}
      />
// ....
GuySartorelli commented 1 month ago

Spike complete and discussed. Next step is https://github.com/silverstripe/silverstripe-admin/issues/1747