{"action":"created","issue":{"url":"https://api.github.com/repos/jaredpalmer/formik/issues/692","repository_url":"https://api.github.com/repos/jaredpalmer/formik","labels_url":"https://api.github.com/repos/jaredpalmer/formik/issues/692/labels{/name}","comments_url":"https://api.github.com/repos/jaredpalmer/formik/issues/692/comments","events_url":"https://api.github.com/repos/jaredpalmer/formik/issues/692/events","html_url":"https://github.com/jaredpalmer/formik/issues/692","id":331985863,"node_id":"MDU6SXNzdWUzMzE5ODU4NjM=","number":692,"title":"Using setFieldValue for one field, based on input of another","user":{"login":"btmdave","id":28645,"node_id":"MDQ6VXNlcjI4NjQ1","avatar_url":"https://avatars1.githubusercontent.com/u/28645?v=4","gravatar_id":"","url":"https://api.github.com/users/btmdave","html_url":"https://github.com/btmdave","followers_url":"https://api.github.com/users/btmdave/followers","following_url":"https://api.github.com/users/btmdave/following{/other_user}","gists_url":"https://api.github.com/users/btmdave/gists{/gist_id}","starred_url":"https://api.github.com/users/btmdave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btmdave/subscriptions","organizations_url":"https://api.github.com/users/btmdave/orgs","repos_url":"https://api.github.com/users/btmdave/repos","events_url":"https://api.github.com/users/btmdave/events{/privacy}","received_events_url":"https://api.github.com/users/btmdave/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-13T13:05:15Z","updated_at":"2018-06-15T22:00:59Z","closed_at":null,"author_association":"NONE","body":"I'm not sure if this is not supported or if there's an alternative solution currently, but I'm trying to update one field, based on the `onChange` input of another.\r\n\r\nFor example:\r\n\r\n```\r\nconst onEmailChange = (e, setFieldValue) => {\r\n  const domain = e.target.value.replace(/.*@/, '')\r\n  setFieldValue('mail.domain', domain, false)\r\n}\r\n\r\nconst Form = ({ data }) => {\r\n  return (\r\n    <Formik\r\n      initialValues={data}\r\n      render={({\r\n        values,\r\n        errors,\r\n        handleSubmit,\r\n        handleChange,\r\n        isSubmitting,\r\n        setFieldValue\r\n      }) => (\r\n        <form onSubmit={handleSubmit}>\r\n          <Input\r\n            type=\"text\"\r\n            name=\"mail.email\"\r\n            value={values.mail.email}\r\n            onChange={ev => onEmailChange(ev, setFieldValue)}\r\n          />\r\n          <Input\r\n            type=\"text\"\r\n            name=\"mail.domain\"\r\n            value={values.mail.domain}\r\n          />\r\n        </form>\r\n      )}\r\n    />\r\n  )\r\n}\r\n```\r\n\r\nThis is attempting to set the value of `mail.domain` based on the input of `mail.email`.  The problem is that when calling `setFieldValue`, it seems to stop updating the field as you type and just gets replaced with each new letter."},"comment":{"url":"https://api.github.com/repos/jaredpalmer/formik/issues/comments/397753240","html_url":"https://github.com/jaredpalmer/formik/issues/692#issuecomment-397753240","issue_url":"https://api.github.com/repos/jaredpalmer/formik/issues/692","id":397753240,"node_id":"MDEyOklzc3VlQ29tbWVudDM5Nzc1MzI0MA==","user":{"login":"IgorSzyporyn","id":6172338,"node_id":"MDQ6VXNlcjYxNzIzMzg=","avatar_url":"https://avatars0.githubusercontent.com/u/6172338?v=4","gravatar_id":"","url":"https://api.github.com/users/IgorSzyporyn","html_url":"https://github.com/IgorSzyporyn","followers_url":"https://api.github.com/users/IgorSzyporyn/followers","following_url":"https://api.github.com/users/IgorSzyporyn/following{/other_user}","gists_url":"https://api.github.com/users/IgorSzyporyn/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorSzyporyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorSzyporyn/subscriptions","organizations_url":"https://api.github.com/users/IgorSzyporyn/orgs","repos_url":"https://api.github.com/users/IgorSzyporyn/repos","events_url":"https://api.github.com/users/IgorSzyporyn/events{/privacy}","received_events_url":"https://api.github.com/users/IgorSzyporyn/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T22:00:59Z","updated_at":"2018-06-15T22:00:59Z","author_association":"NONE","body":"As for alternative solution - try this\r\n\r\n```\r\nconst onEmailChange = (e, onChange, form) => {\r\n  const domain = e.target.value.replace(/.*@/, '')\r\n  onChange(e)\r\n  form.setFieldValue('mail.domain', domain)\r\n}\r\n\r\nconst Form = ({ data }) => {\r\n  return (\r\n    <Formik\r\n      initialValues={data}\r\n      render={({ values, handleSubmit, onChange }) => (\r\n        <Form onSubmit={handleSubmit}>\r\n          <Field\r\n            name=\"mail.email\"\r\n            value={values.mail.mail}\r\n            render={({ field, form }) => (\r\n              <input\r\n                name={field.name}\r\n                value={field.value}\r\n                onChange={e => {\r\n                  onEmailChange(e, onChange, form)\r\n                }}\r\n              />\r\n            )}\r\n          />\r\n          <input type=\"text\" name=\"mail.domain\" value={values.mail.domain} />\r\n        </Form>\r\n      )}\r\n    />\r\n  )\r\n}\r\n```"}}
{"actor":{"display_login":"IgorSzyporyn"}}