title: Antd Select form item keyboard behavior problem
body: <p>I have a form which for the most part works fine. But one thing bugs me about it is the Select item for imputing a person's state (see screenshot below). It works fine with the mouse, but if you're tabbing through the form and tab to the State field, then type a state like "CA" for California, then tab to the next field (zipcode), the State field resets to blank. I would like it to stay populated with CA if it matched one of the selector's options.</p>
  
  <p>It <em>does</em> work if i type "CA" and hit enter to advance to the next field, but that doesn't seem intuitive as to how forms normally work. It also works if I just use my mouse to select the field. I've been looking over the antd documentation on a Select and don't see anything jumping out at me that might control this. Maybe i'm missing something and i need to do some kind of onchange function?</p>
  
  <p>Anyways, seems like a fairly simple problem but the solution is eluding me.</p>
  
  <p><a href="https://i.stack.imgur.com/rrder.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rrder.png" alt="Example"></a></p>
  
  <p>The select form item's code:</p>
  
  <pre class="lang-js prettyprint-override"><code>                              &lt;Form.Item name={[field.name, "state"]} fieldKey={[field.fieldKey, "state"]} rules={rules}&gt;
                                  &lt;Select
                                    showSearch
                                    placeholder="State"
                                    defaultActiveFirstOption={true}
                                  &gt;
                                    &lt;Option value="AL"&gt;AL&lt;/Option&gt;
                                    &lt;Option value="AK"&gt;AK&lt;/Option&gt;
                                    &lt;Option value="AZ"&gt;AZ&lt;/Option&gt;
                                    &lt;Option value="AR"&gt;AR&lt;/Option&gt;
                                    &lt;Option value="CA"&gt;CA&lt;/Option&gt;
                                    &lt;Option value="CO"&gt;CO&lt;/Option&gt;
                                    &lt;Option value="CT"&gt;CT&lt;/Option&gt;
                                    &lt;Option value="DE"&gt;DE&lt;/Option&gt;
                                    &lt;Option value="FL"&gt;FL&lt;/Option&gt;
                                    &lt;Option value="GL"&gt;GA&lt;/Option&gt;
                                    &lt;Option value="HI"&gt;HI&lt;/Option&gt;
                                    &lt;Option value="ID"&gt;ID&lt;/Option&gt;
                                    &lt;Option value="IL"&gt;IL&lt;/Option&gt;
                                    &lt;Option value="IN"&gt;IN&lt;/Option&gt;
                                    &lt;Option value="IA"&gt;IA&lt;/Option&gt;
                                    &lt;Option value="KS"&gt;KS&lt;/Option&gt;
                                    &lt;Option value="KY"&gt;KY&lt;/Option&gt;
                                    &lt;Option value="LA"&gt;LA&lt;/Option&gt;
                                    &lt;Option value="ME"&gt;ME&lt;/Option&gt;
                                    &lt;Option value="MD"&gt;MD&lt;/Option&gt;
                                    &lt;Option value="MA"&gt;MA&lt;/Option&gt;
                                    &lt;Option value="MI"&gt;MI&lt;/Option&gt;
                                    &lt;Option value="MN"&gt;MN&lt;/Option&gt;
                                    &lt;Option value="MS"&gt;MS&lt;/Option&gt;
                                    &lt;Option value="MO"&gt;MO&lt;/Option&gt;
                                    &lt;Option value="MT"&gt;MT&lt;/Option&gt;
                                    &lt;Option value="NE"&gt;NE&lt;/Option&gt;
                                    &lt;Option value="NV"&gt;NV&lt;/Option&gt;
                                    &lt;Option value="NH"&gt;NH&lt;/Option&gt;
                                    &lt;Option value="NJ"&gt;NJ&lt;/Option&gt;
                                    &lt;Option value="NM"&gt;NM&lt;/Option&gt;
                                    &lt;Option value="NY"&gt;NY&lt;/Option&gt;
                                    &lt;Option value="NC"&gt;NC&lt;/Option&gt;
                                    &lt;Option value="ND"&gt;ND&lt;/Option&gt;
                                    &lt;Option value="OH"&gt;OH&lt;/Option&gt;
                                    &lt;Option value="OK"&gt;OK&lt;/Option&gt;
                                    &lt;Option value="OR"&gt;OR&lt;/Option&gt;
                                    &lt;Option value="PA"&gt;PA&lt;/Option&gt;
                                    &lt;Option value="RI"&gt;RI&lt;/Option&gt;
                                    &lt;Option value="SC"&gt;SC&lt;/Option&gt;
                                    &lt;Option value="SD"&gt;SD&lt;/Option&gt;
                                    &lt;Option value="TN"&gt;TN&lt;/Option&gt;
                                    &lt;Option value="TX"&gt;TX&lt;/Option&gt;
                                    &lt;Option value="UT"&gt;UT&lt;/Option&gt;
                                    &lt;Option value="VT"&gt;VT&lt;/Option&gt;
                                    &lt;Option value="VA"&gt;VA&lt;/Option&gt;
                                    &lt;Option value="WA"&gt;WA&lt;/Option&gt;
                                    &lt;Option value="WV"&gt;WV&lt;/Option&gt;
                                    &lt;Option value="WI"&gt;WI&lt;/Option&gt;
                                    &lt;Option value="WY"&gt;WY&lt;/Option&gt;
                                    &lt;Option value="AS"&gt;AS&lt;/Option&gt;
                                    &lt;Option value="DC"&gt;DC&lt;/Option&gt;
                                    &lt;Option value="FM"&gt;FM&lt;/Option&gt;
                                    &lt;Option value="GU"&gt;GU&lt;/Option&gt;
                                    &lt;Option value="MH"&gt;MH&lt;/Option&gt;
                                    &lt;Option value="MP"&gt;MP&lt;/Option&gt;
                                    &lt;Option value="PW"&gt;PW&lt;/Option&gt;
                                    &lt;Option value="PR"&gt;PR&lt;/Option&gt;
                                    &lt;Option value="VI"&gt;VI&lt;/Option&gt;
                                  &lt;/Select&gt;
                                &lt;/Form.Item&gt;
  </code></pre>
  
  <p><strong>Update #1</strong></p>
  
  <p>So following the suggestions in the comments (and my noticing a similar approach <a href="https://ant.design/components/form/v3#Replace-validateFieldsAndScroll-with-scrollToField" rel="nofollow noreferrer">here</a> under the form control section), to my class i've added a <code>formRef = React.createRef();</code>.</p>
  
  <p>Then in my Form tag I added a <code>ref={this.formRef}</code> tag. Then modified my Select by adding an onBlur tag that triggers setFieldsValue to set the uppercase version of the input.</p>
  
  <p>This compiles and runs fine. It even outputs the console.log statement. But it does not set the field value for some reason and i'm not sure why.</p>
  
  <pre class="lang-js prettyprint-override"><code>    return (
        &lt;Form
  **      ref={this.formRef}
          name="dynamic_form_item"
          {...formItemLayoutWithOutLabel}
          onFinish={onFinish}
          id="myForm"
          validateMessages={validateMessages}
        &gt;
          {
            &lt;Form.List name="applicants"&gt;
              {(fields, { add, remove }) =&gt; {
                return (
                  &lt;div&gt;
                    {fields.map((field, index) =&gt; (
                      &lt;Form.Item {...formItemLayout} label={`Applicant #${index + 1}`} key={field.key}&gt;
                                &lt;Form.Item name={[field.name, "state"]} fieldKey={[field.fieldKey, "state"]} rules={rules}&gt;
                                  &lt;Select
                                    showSearch
                                    placeholder="State"
                                    defaultActiveFirstOption={true}
  **                                onBlur={(event) =&gt; {
  **                                  console.log("onblur: ", event);
  **                                  this.formRef.current.setFieldsValue({ state: event.target.value.toUpperCase() });
  **                                }}
                                  &gt;
  </code></pre>
  
  <p><strong>Update #2</strong></p>
  
  <p>screenshot of values when onFinish is called. Note this is a dynamic form where user can add additional applicants by clicking an add applicant button. Each applicant has the fields shown including the state they live in.</p>
  
  <pre><code>    const onFinish = (values) =&gt; {
        console.log("onFinish: ", values);
        this.props.onSubmit({
          applicants: values.applicants,
        });
      };
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/alSnP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/alSnP.png" alt="enter image description here"></a></p>
  
  <p><strong>Update #3</strong></p>
  
  <p>Tried to mimic the approach however for some reason in the object being returned by values, state is absent and ultimately i'm getting an uncaught typeerror and state doesn't populate.</p>
  
  <p><a href="https://i.stack.imgur.com/k8Gqw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k8Gqw.png" alt="enter image description here"></a></p>
  
  <pre><code>                              &lt;Form.Item name={[field.name, "state"]} fieldKey={[field.fieldKey, "state"]} rules={rules}&gt;
                                  &lt;Select
                                    showSearch
                                    placeholder="State"
                                    defaultActiveFirstOption={true}
                                    onBlur={(event) =&gt; {
                                      console.log("values", this.formRef.current.getFieldsValue());
                                      console.log("target:", event.target);
                                      console.log("id", event.target.id);
                                      const stateIndex = event.target.getAttribute("aria-activedescendant").split("_").slice(-1);
                                      const values = this.formRef.current.getFieldsValue();
                                      const namePath = event.target.id.split("_");
                                      console.log("namePath", namePath);
                                      values[namePath[0]][namePath[1]][namePath[2]] = event.target.value.toUpperCase() || STATES[stateIndex];
                                      this.formRef.current.setFieldsValue(values);
                                    }}
                                  &gt;
                                    {STATES.map((state) =&gt; (
                                      &lt;Option value={state} key={state}&gt;
                                        {state}
                                      &lt;/Option&gt;
                                    ))}
                                  &lt;/Select&gt;
                                &lt;/Form.Item&gt;
  </code></pre>
  
  <p><strong>Update #4</strong></p>
  
  <p>So sure enough, removal of the name property in the Form tag resolved the above issue and it's working as expected without error. </p>
  
  <p>In the interest of wrapping up this question in hopes it may help someone else, I wanted to capture the solution. Ultimately the solution amounted to making it so when the user tabs out of the field in question, the field's value gets set to what the user typed. This was done by adding the onBlur tag to my antd Select tag. onBlur fires when the user tabs out of the field. Then making it set the field to the characters entered. Which turned out to be more complicated then I would've thought due to my use of a dyanmic form and nested object array (applicants).</p>
  
  <p>Note the state now shows up under value and the namepath matches what the code expects. </p>
  
  <p><a href="https://i.stack.imgur.com/xfC2D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xfC2D.png" alt="enter image description here"></a></p>
  
  <p>My final code up until this point looks like this</p>
  
  <pre><code>import React from "react";
  import { Form, Input, Col, Row, Select, Button } from "antd";
  import { PlusOutlined, MinusCircleTwoTone } from "@ant-design/icons";
  
  const InputGroup = Input.Group;
  const Option = Select.Option;
  const { TextArea } = Input;
  const maxApplicants = 4;
  
  const rules = [{ required: true }];
  
  const STATES = [
    "AL",
    "AK",
    "AZ",
    "AR",
    "CA",
    "CO",
    "CT",
    "DE",
    "DC",
    "FM",
    "FL",
    "GA",
    "GU",
    "HI",
    "ID",
    "IL",
    "IN",
    "IA",
    "KS",
    "KY",
    "LA",
    "ME",
    "MH",
    "MD",
    "MA",
    "MI",
    "MN",
    "MS",
    "MO",
    "MT",
    "NE",
    "NV",
    "NH",
    "NJ",
    "NM",
    "NY",
    "NC",
    "ND",
    "MP",
    "OH",
    "OK",
    "OR",
    "PW",
    "PA",
    "PR",
    "RI",
    "SC",
    "SD",
    "TN",
    "TX",
    "UT",
    "VT",
    "VI",
    "VA",
    "WA",
    "WV",
    "WI",
    "WY",
  ];
  
  const validateMessages = {
    required: "Required!",
    types: {
      email: "Invalid E-mail!",
      number: "Invalid Number!",
    },
    number: {
      range: "Must be between ${min} and ${max}",
    },
  };
  
  const formItemLayout = {
    labelCol: {
      xs: { span: 24 },
      sm: { span: 6 },
    },
    wrapperCol: {
      xs: { span: 36 },
      sm: { span: 16 },
    },
  };
  
  const formItemLayoutWithOutLabel = {
    wrapperCol: {
      xs: { span: 36, offset: 0 },
      sm: { span: 16, offset: 6 },
    },
  };
  
  export default class TenantForm extends React.Component {
    constructor(props) {
      super(props);
  
      this.state = {
        applicants: [
          {
            firstName: props.tenant ? props.tenant.first : "",
            middleName: props.tenant ? props.tenant.middle : "",
            lastName: props.tenant ? props.tenant.last : "",
            street: props.tenant ? props.tenant.street : "",
            city: props.tenant ? props.tenant.city : "",
            state: props.tenant ? props.tenant.state : "",
            zipcode: props.tenant ? props.tenant.zipcode : "",
          },
        ],
        error: "",
      };
    }
  
    formRef = React.createRef();
  
    render() {
      const onFinish = (values) =&gt; {
        console.log("onFinish: ", values);
        this.props.onSubmit({
          applicants: values.applicants,
        });
      };
  
      return (
        &lt;Form
          ref={this.formRef}
          {...formItemLayoutWithOutLabel}
          onFinish={onFinish}
          id="myForm"
          validateMessages={validateMessages}
          initialValues={{ applicants: [{ firstName: "" }] }}
        &gt;
          {
            &lt;Form.List name="applicants"&gt;
              {(fields, { add, remove }) =&gt; {
                return (
                  &lt;div&gt;
                    {fields.map((field, index) =&gt; (
                      &lt;Form.Item {...formItemLayout} label={`Applicant #${index + 1}`} key={field.key}&gt;
                        &lt;Row key={field.key} gutter={[0, 8]} justify="start"&gt;
                          &lt;Col&gt;
                            &lt;Row gutter={[4, 4]}&gt;
                              &lt;Col span={7}&gt;
                                &lt;Form.Item name={[field.name, "firstName"]} fieldKey={[field.fieldKey, "firstName"]} rules={rules}&gt;
                                  &lt;Input placeholder="First Name" /&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                              &lt;Col span={7}&gt;
                                &lt;Form.Item name={[field.name, "middleName"]} fieldKey={[field.fieldKey, "middleName"]} initialValue=""&gt;
                                  &lt;Input placeholder="Middle Name" /&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                              &lt;Col span={9}&gt;
                                &lt;Form.Item name={[field.name, "lastName"]} fieldKey={[field.fieldKey, "lastName"]} rules={rules}&gt;
                                  &lt;Input placeholder="Last Name" /&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                              &lt;Col flex="none"&gt;
                                {index &gt; 0 ? (
                                  &lt;MinusCircleTwoTone
                                    className="dynamic-delete-button"
                                    onClick={() =&gt; {
                                      remove(field.name);
                                    }}
                                  /&gt;
                                ) : null}
                              &lt;/Col&gt;
                            &lt;/Row&gt;
                            &lt;Row gutter={[4, 4]}&gt;
                              &lt;Col span={23}&gt;
                                &lt;Form.Item name={[field.name, "address"]} fieldKey={[field.fieldKey, "address"]} rules={rules}&gt;
                                  &lt;Input placeholder="Address" /&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                            &lt;/Row&gt;
                            &lt;Row gutter={[4, 4]}&gt;
                              &lt;Col span={12}&gt;
                                &lt;Form.Item name={[field.name, "city"]} fieldKey={[field.fieldKey, "city"]} rules={rules}&gt;
                                  &lt;Input placeholder="City" /&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                              &lt;Col span={5}&gt;
                                &lt;Form.Item name={[field.name, "state"]} fieldKey={[field.fieldKey, "state"]} rules={rules}&gt;
                                  &lt;Select
                                    showSearch
                                    placeholder="State"
                                    defaultActiveFirstOption={true}
                                    onBlur={(event) =&gt; {
                                      console.log("values", this.formRef.current.getFieldsValue());
                                      console.log("target:", event.target);
                                      console.log("id", event.target.id);
                                      const stateIndex = event.target.getAttribute("aria-activedescendant").split("_").slice(-1);
                                      const values = this.formRef.current.getFieldsValue();
                                      const namePath = event.target.id.split("_");
                                      console.log("namePath", namePath);
                                      values[namePath[0]][namePath[1]][namePath[2]] = event.target.value.toUpperCase() || STATES[stateIndex];
                                      this.formRef.current.setFieldsValue(values);
                                    }}
                                  &gt;
                                    {STATES.map((state) =&gt; (
                                      &lt;Option value={state} key={state}&gt;
                                        {state}
                                      &lt;/Option&gt;
                                    ))}
                                  &lt;/Select&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                              &lt;Col span={6}&gt;
                                &lt;Form.Item name={[field.name, "zipcode"]} fieldKey={[field.fieldKey, "zipcode"]} rules={rules}&gt;
                                  &lt;Input placeholder="Zip Code" /&gt;
                                &lt;/Form.Item&gt;
                              &lt;/Col&gt;
                            &lt;/Row&gt;
                          &lt;/Col&gt;
                        &lt;/Row&gt;
                      &lt;/Form.Item&gt;
                    ))}
                    &lt;Form.Item&gt;
                      {console.log("count:", fields.length)}
                      {fields.length &lt; maxApplicants ? (
                        &lt;Button
                          type="dashed"
                          onClick={() =&gt; {
                            add();
                          }}
                          style={{ width: "100%" }}
                        &gt;
                          &lt;PlusOutlined /&gt; Add Applicant
                        &lt;/Button&gt;
                      ) : null}
                    &lt;/Form.Item&gt;
                  &lt;/div&gt;
                );
              }}
            &lt;/Form.List&gt;
          }
        &lt;/Form&gt;
      );
    }
  }
  
  </code></pre>