field-form icon indicating copy to clipboard operation
field-form copied to clipboard

Propogate Fields state to Form

Open makarov-roman opened this issue 4 years ago • 3 comments

What problem does this feature solve?

It allows to get the current state of form (touched, valid) without iteration among all fields. There are multiple use-cases:

  • block submit button until form is valid
  • block application state if there are any invalid fields
  • disable auto-save to prevent invalid data from saving on backend for editing

What does the proposed API look like?

I expect FormInstance to have methods/props isValid(are all fields valid), isTouched(is any field touched) The similar approach is implemented among such libraries as

  • Formik https://jaredpalmer.com/formik/docs/overview
  • angular's ReactiveForms https://angular.io/api/forms/FormGroup
  • react-final-forms https://final-form.org/docs/final-form/types/FormState

Proposed API: I've used antd for example, if it's not ok I can update with plain rc-field-form

const FormComponent = () => {
  const [form] = Form.useForm()
  return <Form form={form}>
    <Button htmlType="submit" disabled={!form.isValid()}>Ok</Button>
  </Form>
}

makarov-roman avatar Jun 26 '20 14:06 makarov-roman

Any status? I think it's a useful feature.

anhkhoi avatar Aug 26 '21 17:08 anhkhoi

Almost 3 years later, and I would love to have this

ghmendonca avatar Feb 15 '23 07:02 ghmendonca

This would be great to have.

bombillazo avatar Jun 21 '23 21:06 bombillazo