bietkul/react-reactive-form

Add controls to FormGenerator onMount?

bostondevin opened this issue · 2 comments

Is there a way to do this when the form mounts so I can add form fields to the form dynamically?

  const config = {
    controls: {},
  };

  const mountForm = (f) => {
    f.addControl("firstName", Input); // This doesn't work...
    f.addControl("lastName", Input); // This doesn't work...
  };

  return (
    <Form className="grid grid-cols-2 gap-2 p-2">
      <FormGenerator onMount={mountForm} fieldConfig={config} />
    </Form>
  );

@bostondevin No, it is not possible. The second option in addControl method should be an instance of FormGroup, FormControl or FormArray classes.

Thanks! I figured it out with just changing the config around of the FormBuilder