@@ -416,56 +416,58 @@ export class SubmissionSectionUploadFileEditComponent
416416 this . operationsBuilder . remove ( this . pathCombiner . getPath ( path ) ) ;
417417 } ) ;
418418 const accessConditionsToSave = [ ] ;
419- formData . accessConditions
420- . map ( ( accessConditions ) => accessConditions . accessConditionGroup )
421- . filter ( ( accessCondition ) => isNotEmpty ( accessCondition ) )
422- . forEach ( ( accessCondition ) => {
423- let accessConditionOpt ;
424-
425- this . availableAccessConditionOptions
426- . filter ( ( element ) => isNotNull ( accessCondition . name ) && element . name === accessCondition . name [ 0 ] . value )
427- . forEach ( ( element ) => accessConditionOpt = element ) ;
428-
429- if ( accessConditionOpt ) {
430- const currentAccessCondition = Object . assign ( { } , accessCondition ) ;
431- currentAccessCondition . name = this . retrieveValueFromField ( accessCondition . name ) ;
432-
433- /* When start and end date fields are deactivated, their values may be still present in formData,
434- therefore it is necessary to delete them if they're not allowed by the current access condition option. */
435- if ( ! accessConditionOpt . hasStartDate ) {
436- delete currentAccessCondition . startDate ;
437- } else if ( accessCondition . startDate ) {
438- const startDate = this . retrieveValueFromField ( accessCondition . startDate ) ;
439- // Clamp the start date to the maximum, if any, since the
440- // datepicker sometimes exceeds it.
441- let startDateDate = new Date ( startDate ) ;
442- if ( accessConditionOpt . maxStartDate ) {
419+ if ( formData . hasOwnProperty ( 'accessConditions' ) ) {
420+ formData . accessConditions
421+ . filter ( ( accessConditions ) => isNotNull ( accessConditions ) )
422+ . map ( ( accessConditions ) => accessConditions . accessConditionGroup )
423+ . filter ( ( accessCondition ) => isNotEmpty ( accessCondition ) )
424+ . forEach ( ( accessCondition ) => {
425+ let accessConditionOpt ;
426+
427+ this . availableAccessConditionOptions
428+ . filter ( ( element ) => isNotNull ( accessCondition . name ) && element . name === accessCondition . name [ 0 ] . value )
429+ . forEach ( ( element ) => accessConditionOpt = element ) ;
430+
431+ if ( accessConditionOpt ) {
432+ const currentAccessCondition = Object . assign ( { } , accessCondition ) ;
433+ currentAccessCondition . name = this . retrieveValueFromField ( accessCondition . name ) ;
434+
435+ /* When start and end date fields are deactivated, their values may be still present in formData,
436+ therefore it is necessary to delete them if they're not allowed by the current access condition option. */
437+ if ( ! accessConditionOpt . hasStartDate ) {
438+ delete currentAccessCondition . startDate ;
439+ } else if ( accessCondition . startDate ) {
440+ const startDate = this . retrieveValueFromField ( accessCondition . startDate ) ;
441+ // Clamp the start date to the maximum, if any, since the
442+ // datepicker sometimes exceeds it.
443+ let startDateDate = new Date ( startDate ) ;
444+ if ( accessConditionOpt . maxStartDate ) {
443445 const maxStartDateDate = new Date ( accessConditionOpt . maxStartDate ) ;
444446 if ( startDateDate > maxStartDateDate ) {
445- startDateDate = maxStartDateDate ;
447+ startDateDate = maxStartDateDate ;
446448 }
449+ }
450+ currentAccessCondition . startDate = dateToISOFormat ( startDateDate ) ;
447451 }
448- currentAccessCondition . startDate = dateToISOFormat ( startDateDate ) ;
449- }
450- if ( ! accessConditionOpt . hasEndDate ) {
451- delete currentAccessCondition . endDate ;
452- } else if ( accessCondition . endDate ) {
453- const endDate = this . retrieveValueFromField ( accessCondition . endDate ) ;
454- // Clamp the end date to the maximum, if any, since the
455- // datepicker sometimes exceeds it.
456- let endDateDate = new Date ( endDate ) ;
457- if ( accessConditionOpt . maxEndDate ) {
452+ if ( ! accessConditionOpt . hasEndDate ) {
453+ delete currentAccessCondition . endDate ;
454+ } else if ( accessCondition . endDate ) {
455+ const endDate = this . retrieveValueFromField ( accessCondition . endDate ) ;
456+ // Clamp the end date to the maximum, if any, since the
457+ // datepicker sometimes exceeds it.
458+ let endDateDate = new Date ( endDate ) ;
459+ if ( accessConditionOpt . maxEndDate ) {
458460 const maxEndDateDate = new Date ( accessConditionOpt . maxEndDate ) ;
459461 if ( endDateDate > maxEndDateDate ) {
460- endDateDate = maxEndDateDate ;
462+ endDateDate = maxEndDateDate ;
461463 }
464+ }
465+ currentAccessCondition . endDate = dateToISOFormat ( endDateDate ) ;
462466 }
463- currentAccessCondition . endDate = dateToISOFormat ( endDateDate ) ;
467+ accessConditionsToSave . push ( currentAccessCondition ) ;
464468 }
465- accessConditionsToSave . push ( currentAccessCondition ) ;
466- }
467- } ) ;
468-
469+ } ) ;
470+ }
469471 if ( isNotEmpty ( accessConditionsToSave ) ) {
470472 this . operationsBuilder . add ( this . pathCombiner . getPath ( 'accessConditions' ) , accessConditionsToSave , true ) ;
471473 }
0 commit comments