mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 17:41:43 -05:00
Clean up Form component's render function
This commit is contained in:
parent
5378331599
commit
12ec3190ff
1 changed files with 62 additions and 46 deletions
|
@ -990,65 +990,81 @@ class SmartForm extends Component {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------- //
|
||||||
|
// ------------------------- Props to Pass ----------------------------- //
|
||||||
|
// --------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
getWrapperProps = () => ({
|
||||||
|
className: 'document-' + this.getFormType(),
|
||||||
|
});
|
||||||
|
|
||||||
|
getFormProps = () => ({
|
||||||
|
id: this.props.id,
|
||||||
|
onSubmit: this.submitForm,
|
||||||
|
onKeyDown: this.formKeyDown,
|
||||||
|
ref: e => {
|
||||||
|
this.form = e;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
getFormErrorsProps = () => ({
|
||||||
|
errors: this.state.errors
|
||||||
|
});
|
||||||
|
|
||||||
|
getFormGroupProps = group => ({
|
||||||
|
key: group.name,
|
||||||
|
...group,
|
||||||
|
errors: this.state.errors,
|
||||||
|
throwError: this.throwError,
|
||||||
|
currentValues: this.state.currentValues,
|
||||||
|
updateCurrentValues: this.updateCurrentValues,
|
||||||
|
deletedValues: this.state.deletedValues,
|
||||||
|
addToDeletedValues: this.addToDeletedValues,
|
||||||
|
clearFieldErrors: this.clearFieldErrors,
|
||||||
|
formType: this.getFormType(),
|
||||||
|
currentUser: this.props.currentUser,
|
||||||
|
disabled: this.state.disabled,
|
||||||
|
formComponents: mergeWithComponents(this.props.formComponents),
|
||||||
|
});
|
||||||
|
|
||||||
|
getFormSubmitProps = () => ({
|
||||||
|
submitLabel: this.props.submitLabel,
|
||||||
|
cancelLabel: this.props.cancelLabel,
|
||||||
|
revertLabel: this.props.revertLabel,
|
||||||
|
cancelCallback: this.props.cancelCallback,
|
||||||
|
revertCallback: this.props.revertCallback,
|
||||||
|
document: this.getDocument(),
|
||||||
|
deleteDocument:
|
||||||
|
(this.getFormType() === 'edit' &&
|
||||||
|
this.props.showRemove &&
|
||||||
|
this.deleteDocument) ||
|
||||||
|
null,
|
||||||
|
collectionName:this.props.collectionName,
|
||||||
|
currentValues:this.state.currentValues,
|
||||||
|
deletedValues:this.state.deletedValues,
|
||||||
|
errors:this.state.errors,
|
||||||
|
});
|
||||||
|
|
||||||
// --------------------------------------------------------------------- //
|
// --------------------------------------------------------------------- //
|
||||||
// ----------------------------- Render -------------------------------- //
|
// ----------------------------- Render -------------------------------- //
|
||||||
// --------------------------------------------------------------------- //
|
// --------------------------------------------------------------------- //
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const fieldGroups = this.getFieldGroups();
|
|
||||||
const collectionName = this.props.collectionName;
|
|
||||||
const FormComponents = mergeWithComponents(this.props.formComponents);
|
const FormComponents = mergeWithComponents(this.props.formComponents);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'document-' + this.getFormType()}>
|
<div {...this.getWrapperProps()}>
|
||||||
<Formsy.Form
|
<Formsy.Form {...this.getFormProps()}>
|
||||||
id={this.props.id}
|
<FormComponents.FormErrors {...this.getFormErrorsProps()} />
|
||||||
onSubmit={this.submitForm}
|
|
||||||
onKeyDown={this.formKeyDown}
|
|
||||||
ref={e => {
|
|
||||||
this.form = e;
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<FormComponents.FormErrors errors={this.state.errors} />
|
|
||||||
|
|
||||||
{fieldGroups.map(group => (
|
{this.getFieldGroups().map(group => (
|
||||||
<FormComponents.FormGroup
|
<FormComponents.FormGroup {...this.getFormGroupProps(group)} />
|
||||||
key={group.name}
|
|
||||||
{...group}
|
|
||||||
errors={this.state.errors}
|
|
||||||
throwError={this.throwError}
|
|
||||||
currentValues={this.state.currentValues}
|
|
||||||
updateCurrentValues={this.updateCurrentValues}
|
|
||||||
deletedValues={this.state.deletedValues}
|
|
||||||
addToDeletedValues={this.addToDeletedValues}
|
|
||||||
clearFieldErrors={this.clearFieldErrors}
|
|
||||||
formType={this.getFormType()}
|
|
||||||
currentUser={this.props.currentUser}
|
|
||||||
disabled={this.state.disabled}
|
|
||||||
formComponents={FormComponents}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{this.props.repeatErrors && this.renderErrors()}
|
{this.props.repeatErrors && this.renderErrors()}
|
||||||
|
|
||||||
<FormComponents.FormSubmit
|
<FormComponents.FormSubmit {...this.getFormSubmitProps()} />
|
||||||
submitLabel={this.props.submitLabel}
|
|
||||||
cancelLabel={this.props.cancelLabel}
|
|
||||||
revertLabel={this.props.revertLabel}
|
|
||||||
cancelCallback={this.props.cancelCallback}
|
|
||||||
revertCallback={this.props.revertCallback}
|
|
||||||
document={this.getDocument()}
|
|
||||||
deleteDocument={
|
|
||||||
(this.getFormType() === 'edit' &&
|
|
||||||
this.props.showRemove &&
|
|
||||||
this.deleteDocument) ||
|
|
||||||
null
|
|
||||||
}
|
|
||||||
collectionName={collectionName}
|
|
||||||
currentValues={this.state.currentValues}
|
|
||||||
deletedValues={this.state.deletedValues}
|
|
||||||
errors={this.state.errors}
|
|
||||||
/>
|
|
||||||
</Formsy.Form>
|
</Formsy.Form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue