Commit 974e40ec3c2f450bdd7ab18ee8a6802a4914a9be
1 parent
07ce8d1c95
Exists in
master
Steps navigation and validation
Showing
3 changed files
with
156 additions
and
12 deletions
Show diff stats
imports/client/views/core/Form.js
1 | import React, { Component, PropTypes } from 'react' | 1 | import React, { Component, PropTypes } from 'react' |
2 | import isEqual from 'lodash/isEqual' | 2 | import isEqual from 'lodash/isEqual' |
3 | import get from 'lodash/get' | 3 | import get from 'lodash/get' |
4 | import cloneDeep from 'lodash/cloneDeep' | 4 | import cloneDeep from 'lodash/cloneDeep' |
5 | import set from 'lodash/set' | 5 | import set from 'lodash/set' |
6 | 6 | ||
7 | class Form extends Component { | 7 | class Form extends Component { |
8 | constructor(props) { | 8 | constructor(props) { |
9 | super(props) | 9 | super(props) |
10 | this.state = { | 10 | this.state = { |
11 | values: props.initialValues || {}, | 11 | values: props.initialValues || {}, |
12 | dirtyValues: [], | 12 | dirtyValues: [], |
13 | submitted: false | 13 | submitted: false |
14 | } | 14 | } |
15 | this.isPristine = this.isPristine.bind(this) | 15 | this.isPristine = this.isPristine.bind(this) |
16 | this.isDirty = this.isDirty.bind(this) | 16 | this.isDirty = this.isDirty.bind(this) |
17 | this.isSubmitted = this.isSubmitted.bind(this) | 17 | this.isSubmitted = this.isSubmitted.bind(this) |
18 | this.getValue = this.getValue.bind(this) | 18 | this.getValue = this.getValue.bind(this) |
19 | this.setValue = this.setValue.bind(this) | 19 | this.setValue = this.setValue.bind(this) |
20 | this.setPristine = this.setPristine.bind(this) | 20 | this.setPristine = this.setPristine.bind(this) |
21 | this.setDirty = this.setDirty.bind(this) | 21 | this.setDirty = this.setDirty.bind(this) |
22 | this.resetSubmitted = this.resetSubmitted.bind(this) | ||
22 | } | 23 | } |
23 | 24 | ||
24 | componentWillReceiveProps(nextProps) { | 25 | componentWillReceiveProps(nextProps) { |
25 | if (!isEqual(this.props.initialValues, nextProps.initialValues)) { | 26 | if (!isEqual(this.props.initialValues, nextProps.initialValues)) { |
26 | this.setState(prevState => ({ | 27 | this.setState(prevState => ({ |
27 | values: { ...nextProps.initialValues, ...prevState.values } | 28 | values: { ...nextProps.initialValues, ...prevState.values } |
28 | })) | 29 | })) |
29 | } | 30 | } |
30 | } | 31 | } |
31 | 32 | ||
32 | isPristine(path) { | 33 | isPristine(path) { |
33 | if (path) { | 34 | if (path) { |
34 | return !this.state.dirtyValues.find(dirtyValue => dirtyValue === path) | 35 | return !this.state.dirtyValues.find(dirtyValue => dirtyValue === path) |
35 | } | 36 | } |
36 | return !this.state.dirtyValues.length | 37 | return !this.state.dirtyValues.length |
37 | } | 38 | } |
38 | 39 | ||
39 | isDirty(path) { | 40 | isDirty(path) { |
40 | return !this.isPristine(path) | 41 | return !this.isPristine(path) |
41 | } | 42 | } |
42 | 43 | ||
43 | isSubmitted() { | 44 | isSubmitted() { |
44 | return this.state.submitted | 45 | return this.state.submitted |
45 | } | 46 | } |
46 | 47 | ||
48 | resetSubmitted() { | ||
49 | this.setState({ submitted: false }) | ||
50 | } | ||
51 | |||
47 | getValue(path) { | 52 | getValue(path) { |
48 | if (!path) { | 53 | if (!path) { |
49 | throw new Error(`getValue() requires a path`) | 54 | throw new Error(`getValue() requires a path`) |
50 | } | 55 | } |
51 | return get(this.state.values, path, '') | 56 | return get(this.state.values, path, '') |
52 | } | 57 | } |
53 | 58 | ||
54 | setValue (path, value) { | 59 | setValue (path, value) { |
55 | if (!path) { | 60 | if (!path) { |
56 | throw new Error(`setValue() requires a path`) | 61 | throw new Error(`setValue() requires a path`) |
57 | } | 62 | } |
58 | if (value === undefined) { | 63 | if (value === undefined) { |
59 | throw new Error(`setValue() requires a non-undefined value`) | 64 | throw new Error(`setValue() requires a non-undefined value`) |
60 | } | 65 | } |
61 | this.setState(prevState => { | 66 | this.setState(prevState => { |
62 | const prevValues = prevState.values | 67 | const prevValues = prevState.values |
63 | // Lo-Dash's set() mutates the original value, so we need to make a copy | 68 | // Lo-Dash's set() mutates the original value, so we need to make a copy |
64 | const prevValuesCopy = cloneDeep(prevValues) | 69 | const prevValuesCopy = cloneDeep(prevValues) |
65 | const nextValues = set(prevValuesCopy, path, value) | 70 | const nextValues = set(prevValuesCopy, path, value) |
66 | return { values: nextValues } | 71 | return { values: nextValues } |
67 | }) | 72 | }) |
68 | this.setDirty(path) | 73 | this.setDirty(path) |
69 | } | 74 | } |
70 | 75 | ||
71 | setPristine(path) { | 76 | setPristine(path) { |
72 | if (!path) { | 77 | if (!path) { |
73 | throw new Error(`setPristine() requires a path`) | 78 | throw new Error(`setPristine() requires a path`) |
74 | } | 79 | } |
75 | this.setState(prevState => ({ | 80 | this.setState(prevState => ({ |
76 | dirtyValues: ( | 81 | dirtyValues: ( |
77 | this.isPristine(path) | 82 | this.isPristine(path) |
78 | ? prevState.dirtyValues | 83 | ? prevState.dirtyValues |
79 | : prevState.dirtyValues.filter(dirtyValue => dirtyValue !== path) | 84 | : prevState.dirtyValues.filter(dirtyValue => dirtyValue !== path) |
80 | ) | 85 | ) |
81 | })) | 86 | })) |
82 | } | 87 | } |
83 | 88 | ||
84 | setDirty(path) { | 89 | setDirty(path) { |
85 | if (!path) { | 90 | if (!path) { |
86 | throw new Error(`setDirty() requires a path`) | 91 | throw new Error(`setDirty() requires a path`) |
87 | } | 92 | } |
88 | this.setState(prevState => ({ | 93 | this.setState(prevState => ({ |
89 | dirtyValues: ( | 94 | dirtyValues: ( |
90 | this.isDirty(path) | 95 | this.isDirty(path) |
91 | ? prevState.dirtyValues | 96 | ? prevState.dirtyValues |
92 | : [...prevState.dirtyValues, path] | 97 | : [...prevState.dirtyValues, path] |
93 | ) | 98 | ) |
94 | })) | 99 | })) |
95 | } | 100 | } |
96 | 101 | ||
97 | reset() { | 102 | reset() { |
98 | this.setState({ | 103 | this.setState({ |
99 | values: this.props.initialValues, | 104 | values: this.props.initialValues, |
100 | dirtyValues: [], | 105 | dirtyValues: [], |
101 | submitted: false | 106 | submitted: false |
102 | }) | 107 | }) |
103 | } | 108 | } |
104 | 109 | ||
105 | handleSubmit(event) { | 110 | handleSubmit(event) { |
106 | if (event) { | 111 | if (event) { |
107 | event.preventDefault() | 112 | event.preventDefault() |
108 | } | 113 | } |
109 | this.setState({ submitted: true }) | 114 | this.setState({ submitted: true }) |
110 | if (this.props.onSubmit) { | 115 | if (this.props.onSubmit) { |
111 | this.props.onSubmit(this.state.values) | 116 | this.props.onSubmit(this.state.values) |
112 | } | 117 | } |
113 | } | 118 | } |
114 | 119 | ||
115 | render() { | 120 | render() { |
116 | // eslint-disable-next-line | 121 | // eslint-disable-next-line |
117 | const { initialValues, children, ...rest } = this.props | 122 | const { initialValues, children, ...rest } = this.props |
118 | return ( | 123 | return ( |
119 | <form {...rest} onSubmit={this.handleSubmit}> | 124 | <form {...rest} onSubmit={this.handleSubmit}> |
120 | {children({ | 125 | {children({ |
121 | values: this.state.values, | 126 | values: this.state.values, |
122 | isPristine: this.isPristine, | 127 | isPristine: this.isPristine, |
123 | isDirty: this.isDirty, | 128 | isDirty: this.isDirty, |
124 | isSubmitted: this.isSubmitted, | 129 | isSubmitted: this.isSubmitted, |
125 | getValue: this.getValue, | 130 | getValue: this.getValue, |
126 | setValue: this.setValue, | 131 | setValue: this.setValue, |
127 | setPristine: this.setPristine, | 132 | setPristine: this.setPristine, |
128 | setDirty: this.setDirty, | 133 | setDirty: this.setDirty, |
129 | reset: this.reset | 134 | reset: this.reset, |
135 | resetSubmitted: this.resetSubmitted | ||
130 | })} | 136 | })} |
131 | </form> | 137 | </form> |
132 | ) | 138 | ) |
133 | } | 139 | } |
134 | } | 140 | } |
135 | 141 | ||
136 | Form.propTypes = { | 142 | Form.propTypes = { |
137 | initialValues: PropTypes.object, | 143 | initialValues: PropTypes.object, |
138 | onSubmit: PropTypes.func, | 144 | onSubmit: PropTypes.func, |
139 | children: PropTypes.func.isRequired | 145 | children: PropTypes.func.isRequired |
140 | } | 146 | } |
141 | 147 | ||
142 | Form.defaultProps = { initialValues: {} } | 148 | Form.defaultProps = { initialValues: {} } |
143 | 149 | ||
144 | export default Form | 150 | export default Form |
145 | 151 |
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 } from '../../../core/validations' | 6 | import { isRequired } from '../../../core/validations' |
7 | 7 | ||
8 | export class AddStudentFormContainer extends Component { | 8 | export class AddStudentFormContainer extends Component { |
9 | 9 | ||
10 | constructor(props) { | 10 | constructor(props) { |
11 | super(props) | 11 | super(props) |
12 | this.state = { currentStep: 0 } | 12 | this.state = { currentStep: 0 } |
13 | this.handleNextClick = this.handleNextClick.bind(this) | 13 | this.handleNextClick = this.handleNextClick.bind(this) |
14 | this.handleBackClick = this.handleBackClick.bind(this) | 14 | this.handleBackClick = this.handleBackClick.bind(this) |
15 | this.handleSubmit = this.handleSubmit.bind(this) | ||
15 | } | 16 | } |
16 | 17 | ||
17 | handleNextClick() { | 18 | handleNextClick() { |
19 | console.log('handleNextClick', this.validator.getErrors()) | ||
18 | this.form.handleSubmit() | 20 | this.form.handleSubmit() |
19 | 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 | console.log('no errors') | ||
20 | this.setState({ currentStep: this.state.currentStep + 1 }) | 23 | this.setState({ currentStep: this.state.currentStep + 1 }) |
21 | this.form.reset() | 24 | this.form.resetSubmitted() |
22 | } | 25 | } |
23 | 26 | ||
24 | handleBackClick() { | 27 | handleBackClick() { |
25 | this.setState({ currentStep: this.state.currentStep + -1 }) | 28 | this.setState({ currentStep: this.state.currentStep + -1 }) |
26 | } | 29 | } |
27 | 30 | ||
31 | handleSubmit() { | ||
32 | if (this.state.currentStep === 2) { | ||
33 | alert('should submit') | ||
34 | } | ||
35 | } | ||
36 | |||
28 | render() { | 37 | render() { |
29 | return ( | 38 | return ( |
30 | <Form onSubmit={() => alert('submitted')} ref={form => this.form = form}> | 39 | <Form onSubmit={this.handleSubmit} ref={form => this.form = form}> |
31 | {({ values, setValue, getValue, isSubmitted, isDirty }) => ( | 40 | {({ values, setValue, getValue, isSubmitted, isDirty }) => ( |
32 | <Validator | 41 | <Validator |
33 | values={values} | 42 | values={values} |
34 | ref={validator => this.validator = validator} | 43 | ref={validator => this.validator = validator} |
35 | validations={{ | 44 | validations={{ |
36 | admissionId: [isRequired], | 45 | admissionId: [isRequired], |
37 | }} | 46 | }} |
38 | > | 47 | > |
39 | {({ errors }) => ( | 48 | {({ errors }) => ( |
40 | <StudentForm | 49 | <StudentForm |
41 | isDirty={isDirty} | 50 | isDirty={isDirty} |
42 | setValue={setValue} | 51 | setValue={setValue} |
43 | getValue={getValue} | 52 | getValue={getValue} |
44 | isSubmitted={isSubmitted} | 53 | isSubmitted={isSubmitted} |
45 | errors={errors} | 54 | errors={errors} |
46 | onNextClick={this.handleNextClick} | 55 | onNextClick={this.handleNextClick} |
47 | onBackClick={this.handleBackClick} | 56 | onBackClick={this.handleBackClick} |
48 | currentStep={this.state.currentStep} | 57 | currentStep={this.state.currentStep} |
49 | /> | 58 | /> |
50 | )} | 59 | )} |
51 | </Validator> | 60 | </Validator> |
52 | )} | 61 | )} |
53 | </Form> | 62 | </Form> |
54 | ) | 63 | ) |
55 | } | 64 | } |
56 | } | 65 | } |
57 | 66 |
imports/client/views/org/admin/students/StudentForm.js
1 | import React, { PropTypes } from 'react' | 1 | import React, { PropTypes } from 'react' |
2 | import { | 2 | import { |
3 | Row, | 3 | Row, |
4 | Col, | 4 | Col, |
5 | FormGroup, | 5 | FormGroup, |
6 | FormControl, | 6 | FormControl, |
7 | Button | 7 | Button |
8 | } from 'react-bootstrap' | 8 | } from 'react-bootstrap' |
9 | import DatePicker from 'react-bootstrap-date-picker' | 9 | import DatePicker from 'react-bootstrap-date-picker' |
10 | import Label from '../../../core/Label' | 10 | import Label from '../../../core/Label' |
11 | import Stepper from '../../../core/Stepper' | 11 | import Stepper from '../../../core/Stepper' |
12 | import ErrorLabel from '../../../core/ErrorLabel' | 12 | import ErrorLabel from '../../../core/ErrorLabel' |
13 | 13 | ||
14 | const StudentForm = props => ( | 14 | const StudentForm = props => ( |
15 | <div className="stepy-validation"> | 15 | <div className="stepy-validation"> |
16 | <Stepper | 16 | <Stepper |
17 | steps={[ | 17 | steps={[ |
18 | { | 18 | { |
19 | label: 'Personal data', | 19 | label: 'Personal data', |
20 | active: props.currentStep === 0, | 20 | active: props.currentStep === 0, |
21 | }, | 21 | }, |
22 | { | 22 | { |
23 | label: 'Address', | 23 | label: 'Address', |
24 | active: props.currentStep === 1, | 24 | active: props.currentStep === 1, |
25 | }, | 25 | }, |
26 | { | 26 | { |
27 | label: 'Parent info', | 27 | label: 'Parent info', |
28 | active: props.currentStep === 2, | 28 | active: props.currentStep === 2, |
29 | } | 29 | } |
30 | ]} | 30 | ]} |
31 | /> | 31 | /> |
32 | {props.currentStep === 0 && ( | 32 | {props.currentStep === 0 && ( |
33 | <fieldset title="1"> | 33 | <fieldset title="1"> |
34 | <legend className="text-semibold">Personal data</legend> | 34 | <legend className="text-semibold">Personal data</legend> |
35 | <Row> | 35 | <Row> |
36 | <Col xs={12} sm={6}> | 36 | <Col xs={12} sm={6}> |
37 | <FormGroup controlId="admissionId"> | 37 | <FormGroup controlId="admissionId"> |
38 | <Label required>Admission Id</Label> | 38 | <Label required>Admission Id</Label> |
39 | <FormControl | 39 | <FormControl |
40 | type="text" | 40 | type="text" |
41 | value={props.getValue('admissionId')} | 41 | value={props.getValue('admissionId')} |
42 | placeholder="admission Id" | 42 | placeholder="admission Id" |
43 | onChange={e => props.setValue('admissionId', e.target.value)} | 43 | onChange={e => props.setValue('admissionId', e.target.value)} |
44 | /> | 44 | /> |
45 | {props.isSubmitted() && props.errors && props.errors.admissionId && ( | 45 | {props.isSubmitted() && props.errors && props.errors.admissionId && ( |
46 | <ErrorLabel> {props.errors.admissionId} </ErrorLabel> | 46 | <ErrorLabel> {props.errors.admissionId} </ErrorLabel> |
47 | )} | 47 | )} |
48 | </FormGroup> | 48 | </FormGroup> |
49 | </Col> | 49 | </Col> |
50 | <Col xs={12} sm={6}> | 50 | <Col xs={12} sm={6}> |
51 | <FormGroup controlId="firstName"> | 51 | <FormGroup controlId="firstName"> |
52 | <Label>First Name</Label> | 52 | <Label>First Name</Label> |
53 | <FormControl | 53 | <FormControl |
54 | type="text" | 54 | type="text" |
55 | value={props.getValue('firstName')} | 55 | value={props.getValue('firstName')} |
56 | placeholder="First Name" | 56 | placeholder="First Name" |
57 | onChange={e => props.setValue('firstName', e.target.value)} | 57 | onChange={e => props.setValue('firstName', e.target.value)} |
58 | /> | 58 | /> |
59 | </FormGroup> | 59 | </FormGroup> |
60 | </Col> | 60 | </Col> |
61 | </Row> | 61 | </Row> |
62 | <Row> | 62 | <Row> |
63 | <Col xs={12} sm={6}> | 63 | <Col xs={12} sm={6}> |
64 | <FormGroup controlId="middleName"> | 64 | <FormGroup controlId="middleName"> |
65 | <Label>Middle Name</Label> | 65 | <Label>Middle Name</Label> |
66 | <FormControl | 66 | <FormControl |
67 | type="text" | 67 | type="text" |
68 | value={props.getValue('middleName')} | 68 | value={props.getValue('middleName')} |
69 | placeholder="Middle Name" | 69 | placeholder="Middle Name" |
70 | onChange={e => props.setValue('middleName', e.target.value)} | 70 | onChange={e => props.setValue('middleName', e.target.value)} |
71 | /> | 71 | /> |
72 | </FormGroup> | 72 | </FormGroup> |
73 | </Col> | 73 | </Col> |
74 | <Col xs={12} sm={6}> | 74 | <Col xs={12} sm={6}> |
75 | <FormGroup controlId="lastName"> | 75 | <FormGroup controlId="lastName"> |
76 | <Label>Last Name</Label> | 76 | <Label>Last Name</Label> |
77 | <FormControl | 77 | <FormControl |
78 | type="text" | 78 | type="text" |
79 | value={props.getValue('lastName')} | 79 | value={props.getValue('lastName')} |
80 | placeholder="Last Name" | 80 | placeholder="Last Name" |
81 | onChange={e => props.setValue('lastName', e.target.value)} | 81 | onChange={e => props.setValue('lastName', e.target.value)} |
82 | /> | 82 | /> |
83 | </FormGroup> | 83 | </FormGroup> |
84 | </Col> | 84 | </Col> |
85 | </Row> | 85 | </Row> |
86 | <Row> | 86 | <Row> |
87 | <Col xs={12} sm={6}> | 87 | <Col xs={12} sm={6}> |
88 | <FormGroup controlId="email"> | 88 | <FormGroup controlId="email"> |
89 | <Label>Email</Label> | 89 | <Label>Email</Label> |
90 | <FormControl | 90 | <FormControl |
91 | type="email" | 91 | type="email" |
92 | value={props.getValue('email')} | 92 | value={props.getValue('email')} |
93 | placeholder="Email" | 93 | placeholder="Email" |
94 | onChange={e => props.setValue('email', e.target.value)} | 94 | onChange={e => props.setValue('email', e.target.value)} |
95 | /> | 95 | /> |
96 | </FormGroup> | 96 | </FormGroup> |
97 | </Col> | 97 | </Col> |
98 | <Col xs={12} sm={6}> | 98 | <Col xs={12} sm={6}> |
99 | <FormGroup> | 99 | <FormGroup> |
100 | <Label>Date of birth</Label> | 100 | <Label>Date of birth</Label> |
101 | <DatePicker | 101 | <DatePicker |
102 | id="dob" | 102 | id="dob" |
103 | value={props.getValue('dob')} | 103 | value={props.getValue('dob')} |
104 | onChange={value => props.setValue('dob', value)} | 104 | onChange={value => props.setValue('dob', value)} |
105 | /> | 105 | /> |
106 | </FormGroup> | 106 | </FormGroup> |
107 | </Col> | 107 | </Col> |
108 | </Row> | 108 | </Row> |
109 | <Row> | 109 | <Row> |
110 | <Col xs={12} sm={6}> | 110 | <Col xs={12} sm={6}> |
111 | <FormGroup controlId="formControlsSelect"> | 111 | <FormGroup controlId="formControlsSelect"> |
112 | <Label>Gender</Label> | 112 | <Label>Gender</Label> |
113 | <FormControl componentClass="select" | 113 | <FormControl componentClass="select" |
114 | placeholder="select" | 114 | placeholder="select" |
115 | value={props.getValue('gender')} | 115 | value={props.getValue('gender')} |
116 | onChange={e => props.setValue('gender', e.target.value)} | 116 | onChange={e => props.setValue('gender', e.target.value)} |
117 | > | 117 | > |
118 | <option value="male">Male</option> | 118 | <option value="male">Male</option> |
119 | <option value="female">Female</option> | 119 | <option value="female">Female</option> |
120 | </FormControl> | 120 | </FormControl> |
121 | </FormGroup> | 121 | </FormGroup> |
122 | </Col> | 122 | </Col> |
123 | </Row> | 123 | </Row> |
124 | </fieldset> | 124 | </fieldset> |
125 | )} | 125 | )} |
126 | {props.currentStep === 1 && ( | 126 | {props.currentStep === 1 && ( |
127 | <fieldset title="2"> | 127 | <fieldset title="2"> |
128 | <legend className="text-semibold">Address</legend> | 128 | <legend className="text-semibold">Address</legend> |
129 | <Row> | 129 | <Row> |
130 | <Col xs={12} sm={6}> | 130 | <Col xs={12} sm={6}> |
131 | <FormGroup controlId="rollNo"> | 131 | <FormGroup controlId="rollNo"> |
132 | <Label>Roll No</Label> | 132 | <Label>Roll No</Label> |
133 | <FormControl | 133 | <FormControl |
134 | type="text" | 134 | type="text" |
135 | value={props.getValue('rollNo')} | 135 | value={props.getValue('rollNo')} |
136 | placeholder="Roll No" | 136 | placeholder="Roll No" |
137 | onChange={e => props.setValue('rollNo', e.target.value)} | 137 | onChange={e => props.setValue('rollNo', e.target.value)} |
138 | /> | 138 | /> |
139 | </FormGroup> | 139 | </FormGroup> |
140 | </Col> | 140 | </Col> |
141 | <Col xs={12} sm={6}> | 141 | <Col xs={12} sm={6}> |
142 | <FormGroup controlId="class"> | 142 | <FormGroup controlId="class"> |
143 | <Label>Class</Label> | 143 | <Label>Class</Label> |
144 | <FormControl | 144 | <FormControl |
145 | type="text" | 145 | type="text" |
146 | value={props.getValue('class')} | 146 | value={props.getValue('class')} |
147 | placeholder="7" | 147 | placeholder="7" |
148 | onChange={e => props.setValue('class', e.target.value)} | 148 | onChange={e => props.setValue('class', e.target.value)} |
149 | /> | 149 | /> |
150 | </FormGroup> | 150 | </FormGroup> |
151 | </Col> | 151 | </Col> |
152 | </Row> | 152 | </Row> |
153 | <Row> | 153 | <Row> |
154 | <Col xs={12} sm={6}> | 154 | <Col xs={12} sm={6}> |
155 | <FormGroup controlId="section"> | 155 | <FormGroup controlId="section"> |
156 | <Label>Section</Label> | 156 | <Label>Section</Label> |
157 | <FormControl | 157 | <FormControl |
158 | type="text" | 158 | type="text" |
159 | value={props.getValue('section')} | 159 | value={props.getValue('section')} |
160 | placeholder="B" | 160 | placeholder="B" |
161 | onChange={e => props.setValue('section', e.target.value)} | 161 | onChange={e => props.setValue('section', e.target.value)} |
162 | /> | 162 | /> |
163 | </FormGroup> | 163 | </FormGroup> |
164 | </Col> | 164 | </Col> |
165 | <Col xs={12} sm={6}> | 165 | <Col xs={12} sm={6}> |
166 | <FormGroup controlId="community"> | 166 | <FormGroup controlId="community"> |
167 | <Label>Community</Label> | 167 | <Label>Community</Label> |
168 | <FormControl | 168 | <FormControl |
169 | type="text" | 169 | type="text" |
170 | value={props.getValue('community')} | 170 | value={props.getValue('community')} |
171 | placeholder="General" | 171 | placeholder="General" |
172 | onChange={e => props.setValue('community', e.target.value)} | 172 | onChange={e => props.setValue('community', e.target.value)} |
173 | /> | 173 | /> |
174 | </FormGroup> | 174 | </FormGroup> |
175 | </Col> | 175 | </Col> |
176 | </Row> | 176 | </Row> |
177 | <Row> | 177 | <Row> |
178 | <Col xs={12} sm={6}> | 178 | <Col xs={12} sm={6}> |
179 | <FormGroup controlId="bloodGroup"> | 179 | <FormGroup controlId="bloodGroup"> |
180 | <Label>bloodGroup</Label> | 180 | <Label>bloodGroup</Label> |
181 | <FormControl | 181 | <FormControl |
182 | type="text" | 182 | type="text" |
183 | value={props.getValue('bloodGroup')} | 183 | value={props.getValue('bloodGroup')} |
184 | placeholder="B+" | 184 | placeholder="B+" |
185 | onChange={e => props.setValue('bloodGroup', e.target.value)} | 185 | onChange={e => props.setValue('bloodGroup', e.target.value)} |
186 | /> | 186 | /> |
187 | </FormGroup> | 187 | </FormGroup> |
188 | </Col> | 188 | </Col> |
189 | <Col xs={12} sm={6}> | 189 | <Col xs={12} sm={6}> |
190 | <FormGroup controlId="phone"> | 190 | <FormGroup controlId="phone"> |
191 | <Label>Phone</Label> | 191 | <Label>Phone</Label> |
192 | <FormControl | 192 | <FormControl |
193 | type="text" | 193 | type="text" |
194 | value={props.getValue('phone')} | 194 | value={props.getValue('phone')} |
195 | placeholder="9999999999" | 195 | placeholder="9999999999" |
196 | onChange={e => props.setValue('phone', e.target.value)} | 196 | onChange={e => props.setValue('phone', e.target.value)} |
197 | /> | 197 | /> |
198 | </FormGroup> | 198 | </FormGroup> |
199 | </Col> | 199 | </Col> |
200 | </Row> | 200 | </Row> |
201 | <Row> | 201 | <Row> |
202 | <Col xs={12} sm={6}> | 202 | <Col xs={12} sm={6}> |
203 | <FormGroup controlId="address"> | 203 | <FormGroup controlId="address"> |
204 | <Label>Address</Label> | 204 | <Label>Address</Label> |
205 | <FormControl | 205 | <FormControl |
206 | type="text" | 206 | type="text" |
207 | value={props.getValue('address')} | 207 | value={props.getValue('address')} |
208 | placeholder="#876, Street, town" | 208 | placeholder="#876, Street, town" |
209 | onChange={e => props.setValue('address', e.target.value)} | 209 | onChange={e => props.setValue('address', e.target.value)} |
210 | /> | 210 | /> |
211 | </FormGroup> | 211 | </FormGroup> |
212 | </Col> | 212 | </Col> |
213 | <Col xs={12} sm={6}> | 213 | <Col xs={12} sm={6}> |
214 | <FormGroup controlId="city"> | 214 | <FormGroup controlId="city"> |
215 | <Label>City</Label> | 215 | <Label>City</Label> |
216 | <FormControl | 216 | <FormControl |
217 | type="text" | 217 | type="text" |
218 | value={props.getValue('city')} | 218 | value={props.getValue('city')} |
219 | placeholder="Chennai" | 219 | placeholder="Chennai" |
220 | onChange={e => props.setValue('city', e.target.value)} | 220 | onChange={e => props.setValue('city', e.target.value)} |
221 | /> | 221 | /> |
222 | </FormGroup> | 222 | </FormGroup> |
223 | </Col> | 223 | </Col> |
224 | </Row> | 224 | </Row> |
225 | <Row> | 225 | <Row> |
226 | <Col xs={12} sm={6}> | 226 | <Col xs={12} sm={6}> |
227 | <FormGroup controlId="state"> | 227 | <FormGroup controlId="state"> |
228 | <Label>State</Label> | 228 | <Label>State</Label> |
229 | <FormControl | 229 | <FormControl |
230 | type="text" | 230 | type="text" |
231 | value={props.getValue('state')} | 231 | value={props.getValue('state')} |
232 | placeholder="Tamilnadu" | 232 | placeholder="Tamilnadu" |
233 | onChange={e => props.setValue('state', e.target.value)} | 233 | onChange={e => props.setValue('state', e.target.value)} |
234 | /> | 234 | /> |
235 | </FormGroup> | 235 | </FormGroup> |
236 | </Col> | 236 | </Col> |
237 | </Row> | 237 | </Row> |
238 | </fieldset> | 238 | </fieldset> |
239 | )} | 239 | )} |
240 | {props.currentStep === 2 && ( | ||
241 | <fieldset title="2"> | ||
242 | <legend className="text-semibold">Parent information</legend> | ||
243 | <Row> | ||
244 | <Col xs={12} sm={6}> | ||
245 | <FormGroup controlId="parentName"> | ||
246 | <Label>Parent Name</Label> | ||
247 | <FormControl | ||
248 | type="text" | ||
249 | value={props.getValue('parentName')} | ||
250 | placeholder="John" | ||
251 | onChange={e => props.setValue('parentName', e.target.value)} | ||
252 | /> | ||
253 | </FormGroup> | ||
254 | </Col> | ||
255 | <Col xs={12} sm={6}> | ||
256 | <FormGroup controlId="parentEmail"> | ||
257 | <Label>Parent Email</Label> | ||
258 | <FormControl | ||
259 | type="text" | ||
260 | value={props.getValue('parentEmail')} | ||
261 | placeholder="john@email.com" | ||
262 | onChange={e => props.setValue('parentEmail', e.target.value)} | ||
263 | /> | ||
264 | </FormGroup> | ||
265 | </Col> | ||
266 | </Row> | ||
267 | <Row> | ||
268 | <Col xs={12} sm={6}> | ||
269 | <FormGroup controlId="relation"> | ||
270 | <Label>Relation</Label> | ||
271 | <FormControl | ||
272 | type="text" | ||
273 | value={props.getValue('relation')} | ||
274 | placeholder="Father" | ||
275 | onChange={e => props.setValue('relation', e.target.value)} | ||
276 | /> | ||
277 | </FormGroup> | ||
278 | </Col> | ||
279 | <Col xs={12} sm={6}> | ||
280 | <FormGroup controlId="profession"> | ||
281 | <Label>Profession</Label> | ||
282 | <FormControl | ||
283 | type="text" | ||
284 | value={props.getValue('profession')} | ||
285 | placeholder="Farmer" | ||
286 | onChange={e => props.setValue('profession', e.target.value)} | ||
287 | /> | ||
288 | </FormGroup> | ||
289 | </Col> | ||
290 | </Row> | ||
291 | <Row> | ||
292 | <Col xs={12} sm={6}> | ||
293 | <FormGroup controlId="parentGender"> | ||
294 | <Label>Parent Gender</Label> | ||
295 | <FormControl componentClass="select" | ||
296 | placeholder="select" | ||
297 | value={props.getValue('parentGender')} | ||
298 | onChange={e => props.setValue('parentGender', e.target.value)} | ||
299 | > | ||
300 | <option value="male">Male</option> | ||
301 | <option value="female">Female</option> | ||
302 | </FormControl> | ||
303 | </FormGroup> | ||
304 | </Col> | ||
305 | <Col xs={12} sm={6}> | ||
306 | <FormGroup controlId="parentPhone"> | ||
307 | <Label>Parent Phone</Label> | ||
308 | <FormControl | ||
309 | type="text" | ||
310 | value={props.getValue('parentPhone')} | ||
311 | placeholder="9876543210" | ||
312 | onChange={e => props.setValue('parentPhone', e.target.value)} | ||
313 | /> | ||
314 | </FormGroup> | ||
315 | </Col> | ||
316 | </Row> | ||
317 | <Row> | ||
318 | <Col xs={12} sm={6}> | ||
319 | <FormGroup controlId="parentAddress"> | ||
320 | <Label>Parent Address</Label> | ||
321 | <FormControl | ||
322 | type="text" | ||
323 | value={props.getValue('parentAddress')} | ||
324 | placeholder="#12, street, town" | ||
325 | onChange={e => props.setValue('parentAddress', e.target.value)} | ||
326 | /> | ||
327 | </FormGroup> | ||
328 | </Col> | ||
329 | <Col xs={12} sm={6}> | ||
330 | <FormGroup controlId="parentCity"> | ||
331 | <Label>Parent City</Label> | ||
332 | <FormControl | ||
333 | type="text" | ||
334 | value={props.getValue('parentCity')} | ||
335 | placeholder="Chennai" | ||
336 | onChange={e => props.setValue('parentCity', e.target.value)} | ||
337 | /> | ||
338 | </FormGroup> | ||
339 | </Col> | ||
340 | </Row> | ||
341 | <Row> | ||
342 | <Col xs={12} sm={6}> | ||
343 | <FormGroup controlId="parentZipcode"> | ||
344 | <Label>Parent Zipcode</Label> | ||
345 | <FormControl | ||
346 | type="text" | ||
347 | value={props.getValue('parentZipcode')} | ||
348 | placeholder="600031" | ||
349 | onChange={e => props.setValue('parentZipcode', e.target.value)} | ||
350 | /> | ||
351 | </FormGroup> | ||
352 | </Col> | ||
353 | </Row> | ||
354 | </fieldset> | ||
355 | )} | ||
240 | <div style={{ textAlign: 'left' }}> | 356 | <div style={{ textAlign: 'left' }}> |
241 | {props.currentStep > 0 && ( | 357 | {props.currentStep > 0 && ( |
242 | <div style={{ display: 'inline-block', marginRight: 10 }}> | 358 | <div style={{ display: 'inline-block', marginRight: 10 }}> |
243 | <Button onClick={props.onBackClick}> | 359 | <Button onClick={props.onBackClick}> |
244 | <i className="icon-arrow-left13 position-left"></i> | 360 | <i className="icon-arrow-left13 position-left"></i> |
245 | BACK | 361 | BACK |
246 | </Button> | 362 | </Button> |
247 | 363 | ||
248 | </div> | 364 | </div> |
249 | )} | 365 | )} |
250 | <div style={{ display: 'inline-block' }}> | 366 | {props.currentStep < 2 && ( |
251 | <Button | 367 | <div style={{ display: 'inline-block' }}> |
252 | bsStyle="primary" | 368 | <Button |
253 | onClick={props.onNextClick} | 369 | bsStyle="primary" |
254 | > | 370 | onClick={props.onNextClick} |
255 | NEXT | 371 | > |
256 | <i className="icon-arrow-right14 position-right" /> | 372 | NEXT |
257 | </Button> | 373 | <i className="icon-arrow-right14 position-right" /> |
258 | </div> | 374 | </Button> |
375 | </div> | ||
376 | )} | ||
377 | {props.currentStep === 2 && ( | ||
378 | <div style={{ display: 'inline-block' }}> | ||
379 | <Button | ||
380 | bsStyle="primary" | ||
381 | onClick={props.onNextClick} | ||
382 | > | ||
383 | SAVE | ||
384 | <i className="fa fa-check" /> | ||
385 | </Button> | ||
386 | </div> | ||
387 | )} | ||
259 | </div> | 388 | </div> |
260 | </div> | 389 | </div> |
261 | ) | 390 | ) |
262 | 391 | ||
263 | StudentForm.propTypes = { | 392 | StudentForm.propTypes = { |
264 | currentStep: PropTypes.number.isRequired, | 393 | currentStep: PropTypes.number.isRequired, |
265 | onNextClick: PropTypes.func.isRequired, | 394 | onNextClick: PropTypes.func.isRequired, |
266 | onBackClick: PropTypes.func.isRequired, | 395 | onBackClick: PropTypes.func.isRequired, |
267 | setValue: PropTypes.func.isRequired, | 396 | setValue: PropTypes.func.isRequired, |
268 | getValue: PropTypes.func.isRequired, | 397 | getValue: PropTypes.func.isRequired, |
269 | } | 398 | } |
270 | 399 | ||
271 | export default StudentForm | 400 | export default StudentForm |
272 | 401 |