I'm using Formik to build my form.
My form has three text area and 1 select dropdown
For select dropdown, I used IssueSelect
(as a FieldArray
in Formik).
And IssueSelect
, I used for both Create and Update Form.
My component looks like this:
const IssueSelect = ({ values }) => (
<FieldArray
name="issues"
render={({ remove, insert, push }) => (
<div>
{values.issues && values.issues.length > 0 ? (
values.issues.map((iselected, index) => (
<div key={uuidv1()}>
<div>
<Field
value={iselected.id}
component="select"
name={`issues.${index}`}
>
{issues.map(issue => (
<option key={issue.id} value={issue.id}>
{issue.name}
</option>
))}
</Field>
</div>
<div>
<button onClick={() => remove(index)}>
<b> - </b>
</button>
<button onClick={() => insert(index, issues[0].id)}>
<b> + </b>
</button>
</div>
</div>
))
) : (
<button onClick={() => push(issues[0].id)}>
<b> + </b> Add new issue
</button>
)}
</div>
)}
/>
);
export default IssueSelect;
In Create Form, everything is work well.
But Update Form, I passing initialValue to IssueSelect
component, it showed correctly data that I've passed. But I cannot change the option in the select box.
I've set default value by passing value={iselected.id}
When I pass this props, In Create Form. It's doesn't work anymore.
You can check my codesand box to see exactly what I mean: https://codesandbox.io/s/rr1o8x3ppq
Thank You in Advance.