import React from 'react'; import reduxForm from '../../redux-form'; import FieldArray from '../../field-array'; import Field from '../../field'; import {getIn, setIn} from '../..'; const validateIsRequired = (value) => !value ? 'Field required.' : undefined; let id = 0; const getId = () => id++; const submitValidate = (values) => { const result = {}; const thirdUserFirstName = getIn(values, 'users[2].firstName'); if (thirdUserFirstName && (thirdUserFirstName.length < 10)) { return setIn(result, 'users[2].firstName', 'Min length should be 10'); } return {}; }; const Friends = (props) => { const {fields, fieldArray} = props; return (
); }; const Users = (props) => { const {fields, pushUser, fieldArray} = props; const push = () => { if (pushUser) { pushUser(fields); } else { fields.push({id: getId()}); } }; return (
); }; const FieldArrayExample = (props) => { const {handleSubmit, pushUser} = props; return (
); }; export default () => { id = 0; return reduxForm({ form: 'fieldArrayExample', validate: submitValidate, })(FieldArrayExample); };