From 974e40ec3c2f450bdd7ab18ee8a6802a4914a9be Mon Sep 17 00:00:00 2001 From: Rafael Arenas Schuchowsky Date: Thu, 23 Mar 2017 19:14:32 -0300 Subject: [PATCH] Steps navigation and validation --- imports/client/views/core/Form.js | 8 +- .../org/admin/students/AddStudentFormContainer.js | 13 +- .../client/views/org/admin/students/StudentForm.js | 147 +++++++++++++++++++-- 3 files changed, 156 insertions(+), 12 deletions(-) diff --git a/imports/client/views/core/Form.js b/imports/client/views/core/Form.js index 6f2f4b8..44b6a18 100644 --- a/imports/client/views/core/Form.js +++ b/imports/client/views/core/Form.js @@ -19,6 +19,7 @@ class Form extends Component { this.setValue = this.setValue.bind(this) this.setPristine = this.setPristine.bind(this) this.setDirty = this.setDirty.bind(this) + this.resetSubmitted = this.resetSubmitted.bind(this) } componentWillReceiveProps(nextProps) { @@ -44,6 +45,10 @@ class Form extends Component { return this.state.submitted } + resetSubmitted() { + this.setState({ submitted: false }) + } + getValue(path) { if (!path) { throw new Error(`getValue() requires a path`) @@ -126,7 +131,8 @@ class Form extends Component { setValue: this.setValue, setPristine: this.setPristine, setDirty: this.setDirty, - reset: this.reset + reset: this.reset, + resetSubmitted: this.resetSubmitted })} ) diff --git a/imports/client/views/org/admin/students/AddStudentFormContainer.js b/imports/client/views/org/admin/students/AddStudentFormContainer.js index e8bec22..77d99e9 100644 --- a/imports/client/views/org/admin/students/AddStudentFormContainer.js +++ b/imports/client/views/org/admin/students/AddStudentFormContainer.js @@ -12,22 +12,31 @@ export class AddStudentFormContainer extends Component { this.state = { currentStep: 0 } this.handleNextClick = this.handleNextClick.bind(this) this.handleBackClick = this.handleBackClick.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) } handleNextClick() { + console.log('handleNextClick', this.validator.getErrors()) this.form.handleSubmit() if (this.validator.getErrors() && Object.keys(this.validator.getErrors()).length > 0) return + console.log('no errors') this.setState({ currentStep: this.state.currentStep + 1 }) - this.form.reset() + this.form.resetSubmitted() } handleBackClick() { this.setState({ currentStep: this.state.currentStep + -1 }) } + handleSubmit() { + if (this.state.currentStep === 2) { + alert('should submit') + } + } + render() { return ( -
alert('submitted')} ref={form => this.form = form}> + this.form = form}> {({ values, setValue, getValue, isSubmitted, isDirty }) => ( ( )} + {props.currentStep === 2 && ( +
+ Parent information + + + + + props.setValue('parentName', e.target.value)} + /> + + + + + + props.setValue('parentEmail', e.target.value)} + /> + + + + + + + + props.setValue('relation', e.target.value)} + /> + + + + + + props.setValue('profession', e.target.value)} + /> + + + + + + + + props.setValue('parentGender', e.target.value)} + > + + + + + + + + + props.setValue('parentPhone', e.target.value)} + /> + + + + + + + + props.setValue('parentAddress', e.target.value)} + /> + + + + + + props.setValue('parentCity', e.target.value)} + /> + + + + + + + + props.setValue('parentZipcode', e.target.value)} + /> + + + +
+ )}
{props.currentStep > 0 && (
@@ -247,15 +363,28 @@ const StudentForm = props => (
)} -
- -
+ {props.currentStep < 2 && ( +
+ +
+ )} + {props.currentStep === 2 && ( +
+ +
+ )}
) -- 2.0.0