@@ -108,7 +108,12 @@ export class UsersUpdateComponent implements OnInit, CanComponentDeactivate {
108108 this . conditionalValidator ( CustomValidators . dateValidRequired ) . bind ( this ) ,
109109 ac => this . validatorService . notDateInFuture$ ( ac )
110110 ] ,
111- age : [ '' , [ Validators . min ( 0 ) , Validators . max ( 120 ) ] ] ,
111+ birthYear : [ '' , [
112+ Validators . min ( 1900 ) ,
113+ Validators . max ( new Date ( ) . getFullYear ( ) - 1 ) ,
114+ Validators . pattern ( / ^ \d { 4 } $ / )
115+ ] ] ,
116+ age : [ '' ] ,
112117 gender : [ '' , this . conditionalValidator ( Validators . required ) . bind ( this ) ] ,
113118 level : [ '' , this . conditionalValidator ( Validators . required ) . bind ( this ) ] ,
114119 betaEnabled : false
@@ -128,6 +133,13 @@ export class UsersUpdateComponent implements OnInit, CanComponentDeactivate {
128133 }
129134
130135 onSubmit ( ) {
136+ // exports don't break: calculate age from birthYear form validation
137+ const birthYear = this . editForm . get ( 'birthYear' ) ?. value ;
138+ if ( birthYear && birthYear . toString ( ) . length === 4 ) {
139+ const calculatedAge = new Date ( ) . getFullYear ( ) - parseInt ( birthYear , 10 ) ;
140+ this . editForm . patchValue ( { age : calculatedAge } , { emitEvent : false } ) ;
141+ }
142+
131143 if ( ! this . editForm . valid ) {
132144 showFormErrors ( this . editForm . controls ) ;
133145 return ;
@@ -138,7 +150,9 @@ export class UsersUpdateComponent implements OnInit, CanComponentDeactivate {
138150
139151 submitUser ( ) {
140152 if ( this . submissionMode ) {
141- this . appendToSurvey ( this . editForm . value ) ;
153+ // Remove birthYear from submitted data
154+ const { birthYear, ...cleanUserData } = this . editForm . value ;
155+ this . appendToSurvey ( cleanUserData ) ;
142156 } else {
143157 const attachment = this . file ? this . createAttachmentObj ( ) : { } ;
144158 this . userService . updateUser ( Object . assign ( { } , this . user , this . editForm . value , attachment ) ) . pipe (
0 commit comments