Skip to content

Instantly share code, notes, and snippets.

@calendee
Last active September 22, 2018 12:44
Show Gist options
  • Select an option

  • Save calendee/5c9805f33177564b51a3ed5e030dc8ab to your computer and use it in GitHub Desktop.

Select an option

Save calendee/5c9805f33177564b51a3ed5e030dc8ab to your computer and use it in GitHub Desktop.
<form onSubmit={handleSubmit}>
<Field
name="firstname"
component={customInput}
type="text"
label="First Name"
validate={[required]}
normalize={capitalize}
/>
<FieldArray name="discountCodes" component={discounts} />
<button type="submit">Submit</button>
</form>
export const discounts = ({ fields }) => (
<div className="custom-field-array-container">
{fields.map((code, index) => (
<div key={index} className="field-array-item">
<Field
name={code}
type="text"
component={customInput}
label={`Discount Code #${index + 1}`}
autoFocus
/>
<button type="button" onClick={() => fields.remove(index)}>
&times;
</button>
</div>
))}
<button type="button" onClick={() => fields.push()}>
Add {!fields.length ? "Discount Code(s)" : "Another Discount Code"}
</button>
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment