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

How to get all form values inside a field?

Open linchen2chris opened this issue 4 years ago • 1 comments

I have a form1 and a nested form2, in form2 I have a field-B, it need field-A's value? field-A was in form1, how can I get field-A's value inside field-B? I can achive this by pass the form to form2, then pass to field-B, then call form.getFieldValue(field-A), any better solution? as I saw rc-field-form use react context, it should be achived by context.consumer.....

linchen2chris avatar Oct 02 '20 15:10 linchen2chris

I think I'm late, but as a first point I don't think you need 1 form inside another, you can achieve it with a single instance is what I think, but if that's the case you can do a useState with field A, something like

 const [fieldA, setFieldA] = useState () 

then you can use the onValuesChange to listen when field A changes and set useState to update the value in Form2, something like

const onValuesChange = (changeValues) => {
  if (changeValues?.fieldA) {
    setFieldA(changeValues.fieldA)
  }
}

I hope I have helped

rivaslive avatar Sep 11 '21 04:09 rivaslive