Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Form component doesn't match upstream #10

Open
nirvdrum opened this issue Dec 17, 2019 · 2 comments
Open

Form component doesn't match upstream #10

nirvdrum opened this issue Dec 17, 2019 · 2 comments

Comments

@nirvdrum
Copy link

This fork of the project has a Form component definition that doesn't match upstream. While there's a fair bit of divergence by virtue of targeting JSX 3, the definition in this fork doesn't appear to be all that usable. In particular, Ant expects you to call a create function to wrap its Form element, giving you something with FormComponentProps, which is needed to validate and extract form values. Basically, it's needed to work with Ant's version of controlled form components. That function is not imported here, so the Form component can't be wrapped.

@nirvdrum
Copy link
Author

This issue is trickier than I thought. Apparently Ant needs the Form wrapper to be a class-based component, which is not what [@react.component] will give you. I came across an article on the changes needed to make the wrapper with functional components.

In the meanwhile, I've discovered that you can use controlled components in Ant's form subsystem just like you would with vanilla React. It's not ideal because you give up all the validation helpers, but it does make it possible to use Ant's styles and rich components.

@JakubMarkiewicz
Copy link
Collaborator

Hey, i totally agree that form component is not quite usable at the moment. At the moment i'm updating bindings only when i need specific stuff at work. As mentioned in #4 i'm planning on doing better bindings when 4.0.0 goes public. Ant team wants to simplify Form component and introduce hooks-like approach instead of Form.create hoc. Example from ant github:

const Demo = () => {
  const [form] = Form.useForm();
  
  const onFinish = () => {
    // Do something...
  };
  
  useEffect(() => {
    // Something like ajax call
    form.setFieldsValue({
      username: 'light',
    });
  }, []);

  return (
    <Form form={form} onFinish={onFinish}>
      <Form.Item name="username" rules={[{ required: true }]}>
        <Input />
      </Form.Item>
    </Form>
  );
}

Take a look here: https://next.ant.design/components/form/?locale=en-US#header
It should be much simpler to bind in the future

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants