Created
July 29, 2016 08:19
-
-
Save deyceg/1bae478ee4bf0b912d31b5b373de9274 to your computer and use it in GitHub Desktop.
This file contains 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
// in constructor iterate over FormWrapper instance this.props.children and decorate "*Field" with <Field> | |
decorateFields = (element) => { | |
const { props: { children } = {} } = element; | |
const { type: { name } = {} } = element; | |
if (typeof element === 'string' || typeof element.type === 'string') return element; | |
//Editable has prop component which is <InlineSelectField> that never gets decorated | |
if (name && name.endsWith('Field')) { // TODO not minficiation safe!!! | |
return this.renderField(element) | |
} else if (children) { | |
return React.cloneElement(element.type, element.props, React.Children.map(children, e => this.decorateFields(e))) | |
} else { | |
return React.cloneElement(element.type, element.props); | |
} | |
}; |
This file contains 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
<FormWrapper form={id} postValidate={postValidate} validate={onValidate} onSubmit={onSubmit} hasError={hasError}> | |
<InlineTextField name="applicantOneName"/> | |
<Editable name="numberOfApplicants" options={numberOfApplicants} component={<InlineSelectField />} /> | |
</FormWrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment