Last active
September 22, 2018 12:44
-
-
Save calendee/5c9805f33177564b51a3ed5e030dc8ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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)}> | |
| × | |
| </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