Commit a928a85941542df1051f6912ac21c83b5d78f7c6
1 parent
b66d66a1a8
Exists in
master
Added male gender by default
Showing
1 changed file
with
8 additions
and
1 deletions
Show diff stats
imports/client/views/org/admin/students/AddStudentFormContainer.js
1 | import React, { Component } from 'react' | 1 | import React, { Component } from 'react' |
2 | import { AddStudentForm } from './addStudentForm' | 2 | import { AddStudentForm } from './addStudentForm' |
3 | import StudentForm from './StudentForm' | 3 | import StudentForm from './StudentForm' |
4 | import Form from '../../../core/Form' | 4 | import Form from '../../../core/Form' |
5 | import Validator from '../../../core/Validator' | 5 | import Validator from '../../../core/Validator' |
6 | import { isRequired, isValidEmail } from '../../../core/validations' | 6 | import { isRequired, isValidEmail } from '../../../core/validations' |
7 | import { addStudentManually } from '/imports/collections/students/methods'; | 7 | import { addStudentManually } from '/imports/collections/students/methods'; |
8 | 8 | ||
9 | export class AddStudentFormContainer extends Component { | 9 | export class AddStudentFormContainer extends Component { |
10 | 10 | ||
11 | constructor(props) { | 11 | constructor(props) { |
12 | super(props) | 12 | super(props) |
13 | this.state = { currentStep: 0 } | 13 | this.state = { currentStep: 0 } |
14 | this.handleNextClick = this.handleNextClick.bind(this) | 14 | this.handleNextClick = this.handleNextClick.bind(this) |
15 | this.handleBackClick = this.handleBackClick.bind(this) | 15 | this.handleBackClick = this.handleBackClick.bind(this) |
16 | this.handleSubmit = this.handleSubmit.bind(this) | 16 | this.handleSubmit = this.handleSubmit.bind(this) |
17 | } | 17 | } |
18 | 18 | ||
19 | handleNextClick() { | 19 | handleNextClick() { |
20 | this.form.handleSubmit() | 20 | this.form.handleSubmit() |
21 | if (this.validator.getErrors() && Object.keys(this.validator.getErrors()).length > 0) return | 21 | if (this.validator.getErrors() && Object.keys(this.validator.getErrors()).length > 0) return |
22 | this.setState({ currentStep: this.state.currentStep + 1 }) | 22 | this.setState({ currentStep: this.state.currentStep + 1 }) |
23 | this.form.resetSubmitted() | 23 | this.form.resetSubmitted() |
24 | } | 24 | } |
25 | 25 | ||
26 | handleBackClick() { | 26 | handleBackClick() { |
27 | this.setState({ currentStep: this.state.currentStep + -1 }) | 27 | this.setState({ currentStep: this.state.currentStep + -1 }) |
28 | } | 28 | } |
29 | 29 | ||
30 | handleSubmit() { | 30 | handleSubmit() { |
31 | if (this.state.currentStep === 2) { | 31 | if (this.state.currentStep === 2) { |
32 | addStudentManually.call(this.form.state.values) | 32 | addStudentManually.call(this.form.state.values) |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | render() { | 36 | render() { |
37 | return ( | 37 | return ( |
38 | <Form onSubmit={this.handleSubmit} ref={form => this.form = form}> | 38 | <Form |
39 | onSubmit={this.handleSubmit} | ||
40 | ref={form => this.form = form} | ||
41 | initialValues={{ | ||
42 | gender: 'male', | ||
43 | parentGender: 'male', | ||
44 | }} | ||
45 | > | ||
39 | {({ values, setValue, getValue, isSubmitted, isDirty }) => ( | 46 | {({ values, setValue, getValue, isSubmitted, isDirty }) => ( |
40 | <Validator | 47 | <Validator |
41 | values={values} | 48 | values={values} |
42 | ref={validator => this.validator = validator} | 49 | ref={validator => this.validator = validator} |
43 | validations={{ | 50 | validations={{ |
44 | admissionId: [isRequired], | 51 | admissionId: [isRequired], |
45 | firstName: [isRequired], | 52 | firstName: [isRequired], |
46 | middleName: [isRequired], | 53 | middleName: [isRequired], |
47 | lastName: [isRequired], | 54 | lastName: [isRequired], |
48 | email: [isRequired, isValidEmail], | 55 | email: [isRequired, isValidEmail], |
49 | dob: [isRequired], | 56 | dob: [isRequired], |
50 | formattedDob: [isRequired], | 57 | formattedDob: [isRequired], |
51 | gender: [isRequired], | 58 | gender: [isRequired], |
52 | rollNo: [(value) => this.state.currentStep === 1 && isRequired(value)], | 59 | rollNo: [(value) => this.state.currentStep === 1 && isRequired(value)], |
53 | class: [(value) => this.state.currentStep === 1 && isRequired(value)], | 60 | class: [(value) => this.state.currentStep === 1 && isRequired(value)], |
54 | section: [(value) => this.state.currentStep === 1 && isRequired(value)], | 61 | section: [(value) => this.state.currentStep === 1 && isRequired(value)], |
55 | community: [(value) => this.state.currentStep === 1 && isRequired(value)], | 62 | community: [(value) => this.state.currentStep === 1 && isRequired(value)], |
56 | bloodGroup: [(value) => this.state.currentStep === 1 && isRequired(value)], | 63 | bloodGroup: [(value) => this.state.currentStep === 1 && isRequired(value)], |
57 | phone: [(value) => this.state.currentStep === 1 && isRequired(value)], | 64 | phone: [(value) => this.state.currentStep === 1 && isRequired(value)], |
58 | address: [(value) => this.state.currentStep === 1 && isRequired(value)], | 65 | address: [(value) => this.state.currentStep === 1 && isRequired(value)], |
59 | city: [(value) => this.state.currentStep === 1 && isRequired(value)], | 66 | city: [(value) => this.state.currentStep === 1 && isRequired(value)], |
60 | state: [(value) => this.state.currentStep === 1 && isRequired(value)], | 67 | state: [(value) => this.state.currentStep === 1 && isRequired(value)], |
61 | parentName: [(value) => this.state.currentStep === 2 && isRequired(value)], | 68 | parentName: [(value) => this.state.currentStep === 2 && isRequired(value)], |
62 | parentEmail: [(value) => this.state.currentStep === 2 && isRequired(value), (value) => this.state.currentStep === 2 && isValidEmail(value)], | 69 | parentEmail: [(value) => this.state.currentStep === 2 && isRequired(value), (value) => this.state.currentStep === 2 && isValidEmail(value)], |
63 | relation: [(value) => this.state.currentStep === 2 && isRequired(value)], | 70 | relation: [(value) => this.state.currentStep === 2 && isRequired(value)], |
64 | profession: [(value) => this.state.currentStep === 2 && isRequired(value)], | 71 | profession: [(value) => this.state.currentStep === 2 && isRequired(value)], |
65 | parentGender: [(value) => this.state.currentStep === 2 && isRequired(value)], | 72 | parentGender: [(value) => this.state.currentStep === 2 && isRequired(value)], |
66 | parentPhone: [(value) => this.state.currentStep === 2 && isRequired(value)], | 73 | parentPhone: [(value) => this.state.currentStep === 2 && isRequired(value)], |
67 | parentAddress: [(value) => this.state.currentStep === 2 && isRequired(value)], | 74 | parentAddress: [(value) => this.state.currentStep === 2 && isRequired(value)], |
68 | parentCity: [(value) => this.state.currentStep === 2 && isRequired(value)], | 75 | parentCity: [(value) => this.state.currentStep === 2 && isRequired(value)], |
69 | parentState: [(value) => this.state.currentStep === 2 && isRequired(value)], | 76 | parentState: [(value) => this.state.currentStep === 2 && isRequired(value)], |
70 | parentZipcode: [(value) => this.state.currentStep === 2 && isRequired(value)], | 77 | parentZipcode: [(value) => this.state.currentStep === 2 && isRequired(value)], |
71 | }} | 78 | }} |
72 | > | 79 | > |
73 | {({ errors }) => ( | 80 | {({ errors }) => ( |
74 | <StudentForm | 81 | <StudentForm |
75 | isDirty={isDirty} | 82 | isDirty={isDirty} |
76 | setValue={setValue} | 83 | setValue={setValue} |
77 | getValue={getValue} | 84 | getValue={getValue} |
78 | isSubmitted={isSubmitted} | 85 | isSubmitted={isSubmitted} |
79 | errors={errors} | 86 | errors={errors} |
80 | onNextClick={this.handleNextClick} | 87 | onNextClick={this.handleNextClick} |
81 | onBackClick={this.handleBackClick} | 88 | onBackClick={this.handleBackClick} |
82 | currentStep={this.state.currentStep} | 89 | currentStep={this.state.currentStep} |
83 | /> | 90 | /> |
84 | )} | 91 | )} |
85 | </Validator> | 92 | </Validator> |
86 | )} | 93 | )} |
87 | </Form> | 94 | </Form> |
88 | ) | 95 | ) |
89 | } | 96 | } |
90 | } | 97 | } |
91 | 98 |