@@ -65,7 +65,7 @@ class RecruitCRMJobApplyContainer extends React.Component {
65
65
onApplyClick ( ) {
66
66
const { applyForJob, job } = this . props ;
67
67
const { formData } = this . state ;
68
- applyForJob ( job . slug , formData ) ;
68
+ applyForJob ( job , formData ) ;
69
69
}
70
70
71
71
validateForm ( ) {
@@ -76,10 +76,27 @@ class RecruitCRMJobApplyContainer extends React.Component {
76
76
'fname' , 'lname' , 'city' , 'reffereal' , 'phone' , 'email' ,
77
77
] ;
78
78
// check required text fields for value
79
+ // check min/max lengths
79
80
_ . each ( requiredTextFields , ( key ) => {
80
81
if ( ! formData [ key ] || ! _ . trim ( formData [ key ] ) ) formErrors [ key ] = 'Required field' ;
81
82
else if ( formData [ key ] && _ . trim ( formData [ key ] ) . length < 2 ) formErrors [ key ] = 'Must be at least 2 characters' ;
82
- else delete formErrors [ key ] ;
83
+ else if ( formData [ key ] && _ . trim ( formData [ key ] ) . length > 2 ) {
84
+ switch ( key ) {
85
+ case 'reffereal' :
86
+ if ( _ . trim ( formData [ key ] ) . length > 2000 ) formErrors [ key ] = 'Must be max 2000 characters' ;
87
+ else delete formErrors [ key ] ;
88
+ break ;
89
+ case 'city' :
90
+ case 'phone' :
91
+ if ( _ . trim ( formData [ key ] ) . length > 50 ) formErrors [ key ] = 'Must be max 50 characters' ;
92
+ else delete formErrors [ key ] ;
93
+ break ;
94
+ default :
95
+ if ( _ . trim ( formData [ key ] ) . length > 40 ) formErrors [ key ] = 'Must be max 40 characters' ;
96
+ else delete formErrors [ key ] ;
97
+ break ;
98
+ }
99
+ } else delete formErrors [ key ] ;
83
100
} ) ;
84
101
// check for selected country
85
102
if ( ! _ . find ( formData . country , { selected : true } ) ) formErrors . country = 'Please, select your country' ;
@@ -175,9 +192,9 @@ function mapStateToProps(state, ownProps) {
175
192
function mapDispatchToActions ( dispatch ) {
176
193
const a = actions . recruit ;
177
194
return {
178
- applyForJob : ( id , payload ) => {
179
- dispatch ( a . applyForJobInit ( id , payload ) ) ;
180
- dispatch ( a . applyForJobDone ( id , payload ) ) ;
195
+ applyForJob : ( job , payload ) => {
196
+ dispatch ( a . applyForJobInit ( job , payload ) ) ;
197
+ dispatch ( a . applyForJobDone ( job , payload ) ) ;
181
198
} ,
182
199
} ;
183
200
}
0 commit comments