Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cb2-15660): fix un numbers #1698

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ViewportScroller } from '@angular/common';
import { Component, OnDestroy, OnInit, inject, input } from '@angular/core';
import { ControlContainer, FormBuilder, FormGroup } from '@angular/forms';
import { ControlContainer, FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { ADRAdditionalNotesNumber } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/adrAdditionalNotesNumber.enum.js';
import { ADRBodyDeclarationTypes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/adrBodyDeclarationType.enum.js';
Expand Down Expand Up @@ -131,12 +131,8 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
'Reference number or UN number 1 is required when selecting Product List'
),
]),
techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo: this.fb.array(
[
this.fb.control<string | null>(null, [
this.commonValidators.maxLength(1500, 'UN number 1 must be less than or equal to 1500 characters'),
]),
],
techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo: this.fb.array<FormControl<string | null>>(
[],
[
this.adrValidators.requiresAllUnNumbersToBePopulated(),
this.adrValidators.requiresAUnNumberOrReferenceNumber(
Expand Down Expand Up @@ -312,9 +308,30 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
}

handleInitialiseUNNumbers() {
this.techRecord()?.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo?.forEach(() =>
this.addUNNumber()
);
const unNumbers = this.techRecord()?.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo;

// If there are un numbers, then prepopulate them
if (Array.isArray(unNumbers) && unNumbers.length > 0) {
unNumbers?.forEach((number, index) => {
this.form.controls.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.push(
this.fb.control<string | null>(number, [
this.commonValidators.maxLength(
1500,
`UN number ${index + 1} must be less than or equal to 1500 characters`
),
])
);
});
}

// Otherwise, add a single empty UN number
else {
this.form.controls.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.push(
this.fb.control<string | null>(null, [
this.commonValidators.maxLength(1500, 'UN number 1 must be less than or equal to 1500 characters'),
])
);
}
}

handleInitialiseSubsequentTankInspections() {
Expand Down
Loading