Sarthak Saxena
Sarthak Saxena

Reputation: 169

How to change the value of a dynamic form field in antd?

I have a dynamic form in antd. I want to change another field's value based on the value of another field. I am using onFieldsChange to detect the required change and then trying to change the value of another field equal to the currently changed value.

const handleFieldsChange = (data) => {
    // console.log(data);

    if (data)
      if (data[0])
        if (data[0].name)
          if (data[0].name[2]) {
            if (data[0].name[2] === 'quantity') {
              // console.log(data[0].value);
              // form.setFieldsValue()
              form.setFieldsValue({
                [[data[0].name[0], data[0].name[1], 'component_pm']]: 5,
              });
            }
            // if (data[0].name[2] === 'kit') {
            // }
          }
  };

I want to put the quantity value in the component_pm field.

The form : enter image description here

Upvotes: 2

Views: 5954

Answers (1)

Ajish V Nair
Ajish V Nair

Reputation: 116

Use setFeilds

setFields([{name:[data[0].name[0], data[0].name[1], 'component_pm'],value:5}])

Upvotes: 4

Related Questions