@@ -91,43 +91,41 @@ export default class Education extends ConsentComponent {
91
91
*/
92
92
onCheckFormValue ( newEducation ) {
93
93
let invalid = false ;
94
- let haveDate = false ;
95
94
const currentDate = new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ;
96
95
97
96
if ( ! _ . trim ( newEducation . schoolCollegeName ) . length ) {
98
97
invalid = true ;
99
98
}
100
99
101
-
102
- if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
100
+ if ( _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
101
+ // If enter End Date, the other becomes mandatory.
102
+ // Not as per requirement, both are optional
103
+ invalid = true ;
104
+ } else if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && _ . isEmpty ( newEducation . timePeriodTo ) ) {
103
105
const fromDate = new Date ( newEducation . timePeriodFrom ) . setHours ( 0 , 0 , 0 , 0 ) ;
104
- const toDate = new Date ( newEducation . timePeriodTo ) . setHours ( 0 , 0 , 0 , 0 ) ;
105
106
106
- if ( fromDate > toDate ) {
107
- haveDate = true ;
107
+ if ( fromDate > currentDate ) {
108
+ invalid = true ; // Start Date should be in past or current
108
109
}
110
+ } else if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
111
+ const fromDate = new Date ( newEducation . timePeriodFrom ) . setHours ( 0 , 0 , 0 , 0 ) ;
112
+ const toDate = new Date ( newEducation . timePeriodTo ) . setHours ( 0 , 0 , 0 , 0 ) ;
109
113
110
114
if ( fromDate > currentDate ) {
111
- haveDate = true ;
115
+ invalid = true ; // Start Date should be in past or current
112
116
}
113
117
114
- if ( ( toDate > currentDate ) && newEducation . graduated ) {
115
- haveDate = true ;
116
- }
117
- }
118
-
119
- if ( ! haveDate
120
- && ! ( _ . isEmpty ( newEducation . timePeriodFrom ) && _ . isEmpty ( newEducation . timePeriodTo ) ) ) {
121
- if ( ! _ . trim ( newEducation . timePeriodFrom ) . length ) {
118
+ if ( fromDate >= toDate ) { // Start Date should be before End Date
122
119
invalid = true ;
123
120
}
124
121
125
- if ( ! _ . trim ( newEducation . timePeriodTo ) . length ) {
126
- invalid = true ;
122
+ if ( newEducation . graduated ) {
123
+ if ( toDate > currentDate ) {
124
+ invalid = true ; // End Date should be in past or current
125
+ }
127
126
}
128
127
}
129
128
130
-
131
129
this . setState ( { formInvalid : invalid } ) ;
132
130
return invalid ;
133
131
}
@@ -140,26 +138,32 @@ export default class Education extends ConsentComponent {
140
138
message : '' ,
141
139
} ;
142
140
143
- if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
144
- let fromDate = new Date ( newEducation . timePeriodFrom ) ;
145
- fromDate = fromDate . setHours ( 0 , 0 , 0 , 0 ) ;
146
- let toDate = new Date ( newEducation . timePeriodTo ) ;
147
- toDate = toDate . setHours ( 0 , 0 , 0 , 0 ) ;
148
141
149
- if ( fromDate > toDate ) {
142
+ if ( _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
143
+ // If enter End Date, the other becomes mandatory.
144
+ // Not as per requirement, both are optional
145
+ result . invalid = true ;
146
+ result . message = 'Start Date cannot be empty' ;
147
+ } else if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && _ . isEmpty ( newEducation . timePeriodTo ) ) {
148
+ const fromDate = new Date ( newEducation . timePeriodFrom ) . setHours ( 0 , 0 , 0 , 0 ) ;
149
+
150
+ if ( fromDate > currentDate ) {
150
151
result . invalid = true ;
151
- result . message = 'Start Date should be before End Date ' ;
152
+ result . message = 'Start Date should be in past or current ' ;
152
153
}
154
+ } else if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
155
+ const fromDate = new Date ( newEducation . timePeriodFrom ) . setHours ( 0 , 0 , 0 , 0 ) ;
156
+ const toDate = new Date ( newEducation . timePeriodTo ) . setHours ( 0 , 0 , 0 , 0 ) ;
153
157
154
158
if ( fromDate > currentDate ) {
155
159
result . invalid = true ;
156
- result . message = result . message . length > 0 ? ` ${ result . message } and in past or current` : 'Start Date should be in past or current' ;
160
+ result . message = 'Start Date should be in past or current' ;
157
161
}
158
- }
159
162
160
- if ( _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
161
- result . invalid = true ;
162
- result . message = 'Due to End Date has date, Start Date should be input' ;
163
+ if ( fromDate >= toDate ) {
164
+ result . invalid = true ;
165
+ result . message = 'Start Date should be before End Date' ;
166
+ }
163
167
}
164
168
165
169
return result ;
@@ -176,17 +180,12 @@ export default class Education extends ConsentComponent {
176
180
if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && ! _ . isEmpty ( newEducation . timePeriodTo ) ) {
177
181
const toDate = new Date ( newEducation . timePeriodTo ) . setHours ( 0 , 0 , 0 , 0 ) ;
178
182
179
- if ( ( toDate > currentDate ) && newEducation . graduated ) {
183
+ if ( newEducation . graduated && ( toDate > currentDate ) ) {
180
184
result . invalid = true ;
181
- result . message = 'End Date (or expected) should be in past or current' ;
185
+ result . message = 'End Date should be in past or current' ;
182
186
}
183
187
}
184
188
185
- if ( ! _ . isEmpty ( newEducation . timePeriodFrom ) && _ . isEmpty ( newEducation . timePeriodTo ) ) {
186
- result . invalid = true ;
187
- result . message = 'Due to Start Date has date, End Date should be input' ;
188
- }
189
-
190
189
return result ;
191
190
}
192
191
@@ -235,6 +234,7 @@ export default class Education extends ConsentComponent {
235
234
showConfirmation : false ,
236
235
indexNo : null ,
237
236
inputChanged : false ,
237
+ isEdit : false ,
238
238
} ) ;
239
239
}
240
240
@@ -295,7 +295,7 @@ export default class Education extends ConsentComponent {
295
295
}
296
296
297
297
if ( educationTrait . traits && educationTrait . traits . data . length > 0 ) {
298
- const newEducationTrait = { ... educationTrait } ;
298
+ const newEducationTrait = _ . cloneDeep ( educationTrait ) ;
299
299
if ( isEdit ) {
300
300
newEducationTrait . traits . data . splice ( indexNo , 1 ) ;
301
301
}
@@ -343,9 +343,6 @@ export default class Education extends ConsentComponent {
343
343
newEducation [ e . target . name ] = e . target . value ;
344
344
} else {
345
345
newEducation [ e . target . name ] = e . target . checked ;
346
- if ( e . target . checked ) {
347
- newEducation . timePeriodTo = '' ;
348
- }
349
346
}
350
347
351
348
this . setState ( { newEducation, inputChanged : true } ) ;
@@ -507,13 +504,18 @@ export default class Education extends ConsentComponent {
507
504
</ div >
508
505
</ div >
509
506
< div styleName = "row" >
510
- < div styleName = " field col-1-no-padding" >
507
+ < div styleName = { ` field ${ _ . isEmpty ( newEducation . timePeriodTo ) ? ' col-1-no-padding' : 'col-1' } ` } >
511
508
< label htmlFor = "timePeriodFrom" >
512
509
Start Date
513
510
< input type = "hidden" />
514
511
</ label >
515
512
</ div >
516
513
< div styleName = "field col-2" >
514
+ {
515
+ ! _ . isEmpty ( newEducation . timePeriodTo ) && (
516
+ < span styleName = "text-required" > * Required</ span >
517
+ )
518
+ }
517
519
< DatePicker
518
520
readOnly
519
521
numberOfMonths = { 1 }
@@ -650,6 +652,11 @@ export default class Education extends ConsentComponent {
650
652
< div styleName = "field col-date" >
651
653
< label htmlFor = "timePeriodFrom" >
652
654
Start Date
655
+ {
656
+ ! _ . isEmpty ( newEducation . timePeriodTo ) && (
657
+ < span styleName = "text-required" > * Required</ span >
658
+ )
659
+ }
653
660
< input type = "hidden" />
654
661
</ label >
655
662
< DatePicker
0 commit comments