Skip to content

Commit

Permalink
Merge branch 'feat/cb2-14457' into feature/VTMDEV-2
Browse files Browse the repository at this point in the history
  • Loading branch information
pbardy2000 committed Nov 18, 2024
2 parents 47b0b01 + b8a8395 commit fa8fb74
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/app/directives/govuk-checkbox/govuk-checkbox.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ export class GovukCheckboxDirective implements OnInit, OnDestroy {
elementRef = inject<ElementRef<HTMLInputElement>>(ElementRef);
controlContainer = inject(ControlContainer);

formControlName = input.required<string>();
controlName = input<string>('', { alias: 'formControlName' });
width = input<FormNodeWidth>();

destroy$ = new ReplaySubject<boolean>(1);

ngOnInit(): void {
const formControlName = this.formControlName();
const control = this.controlContainer.control?.get(formControlName);
const controlName = this.controlName();
const control = this.controlContainer.control?.get(controlName);
if (control) {
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${formControlName}-label`);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${controlName}-label`);
control.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((statusChange) => {
if (statusChange === 'INVALID' && control.touched) {
this.elementRef.nativeElement.classList.add('govuk-checkbox--error');
this.elementRef.nativeElement.setAttribute('aria-describedby', `${formControlName}-error`);
this.elementRef.nativeElement.setAttribute('aria-describedby', `${controlName}-error`);
}

if (statusChange === 'VALID') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export class GovukDateInputDirective implements OnInit, OnDestroy {
controlContainer = inject(ControlContainer);

govukDateInput = input.required<string>();
formControlName = input.required<string>();
controlName = input.required<string>({ alias: 'formControlName' });

destroy$ = new ReplaySubject<boolean>(1);

ngOnInit(): void {
const parent = this.govukDateInput();
const formControlName = this.formControlName();
const id = `${parent}-${formControlName}`;
const controlName = this.controlName();
const id = `${parent}-${controlName}`;

const control = this.controlContainer.control?.get(formControlName);
const control = this.controlContainer.control?.get(controlName);
if (control) {
this.elementRef.nativeElement.setAttribute('id', id);
this.elementRef.nativeElement.setAttribute('name', id);
Expand All @@ -34,7 +34,7 @@ export class GovukDateInputDirective implements OnInit, OnDestroy {
control.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((statusChange) => {
if (statusChange === 'INVALID' && control.touched) {
this.elementRef.nativeElement.classList.add('govuk-input--error');
this.elementRef.nativeElement.setAttribute('aria-describedby', `${formControlName}-error`);
this.elementRef.nativeElement.setAttribute('aria-describedby', `${controlName}-error`);
}

if (statusChange === 'VALID') {
Expand Down
14 changes: 7 additions & 7 deletions src/app/directives/govuk-input/govuk-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ export class GovukInputDirective implements OnInit, OnDestroy {
elementRef = inject<ElementRef<HTMLInputElement>>(ElementRef);
controlContainer = inject(ControlContainer);

formControlName = input.required<string>();
controlName = input.required<string>({ alias: 'formControlName' });

destroy$ = new ReplaySubject<boolean>(1);

ngOnInit(): void {
const formControlName = this.formControlName();
const control = this.controlContainer.control?.get(formControlName);
const controlName = this.controlName();
const control = this.controlContainer.control?.get(controlName);
if (control) {
this.elementRef.nativeElement.setAttribute('id', formControlName);
this.elementRef.nativeElement.setAttribute('name', formControlName);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${formControlName}-label`);
this.elementRef.nativeElement.setAttribute('id', controlName);
this.elementRef.nativeElement.setAttribute('name', controlName);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${controlName}-label`);
this.elementRef.nativeElement.classList.add('govuk-input');

control.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((statusChange) => {
if (statusChange === 'INVALID' && control.touched) {
this.elementRef.nativeElement.classList.add('govuk-input--error');
this.elementRef.nativeElement.setAttribute('aria-describedby', `${formControlName}-error`);
this.elementRef.nativeElement.setAttribute('aria-describedby', `${controlName}-error`);
}

if (statusChange === 'VALID') {
Expand Down
10 changes: 5 additions & 5 deletions src/app/directives/govuk-radio/govuk-radio.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ export class GovukRadioDirective implements OnInit, OnDestroy {
elementRef = inject<ElementRef<HTMLInputElement>>(ElementRef);
controlContainer = inject(ControlContainer);

formControlName = input.required<string>();
controlName = input.required<string>({ alias: 'formControlName' });
width = input<FormNodeWidth>();

destroy$ = new ReplaySubject<boolean>(1);

ngOnInit(): void {
this.elementRef.nativeElement.classList.add('govuk-radios__input');

const formControlName = this.formControlName();
const control = this.controlContainer.control?.get(formControlName);
const controlName = this.controlName();
const control = this.controlContainer.control?.get(controlName);
if (control) {
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${formControlName}-label`);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${controlName}-label`);
control.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((statusChange) => {
if (statusChange === 'INVALID' && control.touched) {
this.elementRef.nativeElement.classList.add('govuk-radio--error');
this.elementRef.nativeElement.setAttribute('aria-describedby', `${formControlName}-error`);
this.elementRef.nativeElement.setAttribute('aria-describedby', `${controlName}-error`);
}

if (statusChange === 'VALID') {
Expand Down
14 changes: 7 additions & 7 deletions src/app/directives/govuk-select/govuk-select.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ export class GovukSelectDirective {
elementRef = inject<ElementRef<HTMLSelectElement>>(ElementRef);
controlContainer = inject(ControlContainer);

formControlName = input.required<string>();
controlName = input.required<string>({ alias: 'formControlName' });

destroy$ = new ReplaySubject<boolean>(1);

ngOnInit(): void {
const formControlName = this.formControlName();
const control = this.controlContainer.control?.get(formControlName);
const controlName = this.controlName();
const control = this.controlContainer.control?.get(controlName);
if (control) {
this.elementRef.nativeElement.setAttribute('id', formControlName);
this.elementRef.nativeElement.setAttribute('name', formControlName);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${formControlName}-label`);
this.elementRef.nativeElement.setAttribute('id', controlName);
this.elementRef.nativeElement.setAttribute('name', controlName);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${controlName}-label`);
this.elementRef.nativeElement.classList.add('govuk-select');

control.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((statusChange) => {
if (statusChange === 'INVALID' && control.touched) {
this.elementRef.nativeElement.classList.add('govuk-select--error');
this.elementRef.nativeElement.setAttribute('aria-describedby', `${formControlName}-error`);
this.elementRef.nativeElement.setAttribute('aria-describedby', `${controlName}-error`);
}

if (statusChange === 'VALID') {
Expand Down
14 changes: 7 additions & 7 deletions src/app/directives/govuk-textarea/govuk-textarea.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ export class GovukTextareaDirective implements OnInit, OnDestroy {
elementRef = inject<ElementRef<HTMLInputElement>>(ElementRef);
controlContainer = inject(ControlContainer);

formControlName = input.required<string>();
controlName = input.required<string>({ alias: 'formControlName' });

destroy$ = new ReplaySubject<boolean>(1);

ngOnInit(): void {
const formControlName = this.formControlName();
const control = this.controlContainer.control?.get(formControlName);
const controlName = this.controlName();
const control = this.controlContainer.control?.get(controlName);
if (control) {
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${formControlName}-label`);
this.elementRef.nativeElement.setAttribute('aria-labelledby', `${controlName}-label`);
this.elementRef.nativeElement.setAttribute('rows', '5');
this.elementRef.nativeElement.setAttribute('id', formControlName);
this.elementRef.nativeElement.setAttribute('name', formControlName);
this.elementRef.nativeElement.setAttribute('id', controlName);
this.elementRef.nativeElement.setAttribute('name', controlName);
this.elementRef.nativeElement.classList.add('govuk-textarea');
this.elementRef.nativeElement.classList.add('govuk-js-character-count');

control.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((statusChange) => {
if (statusChange === 'INVALID' && control.touched) {
this.elementRef.nativeElement.classList.add('govuk-textarea-error');
this.elementRef.nativeElement.setAttribute('aria-describedby', `${formControlName}-error`);
this.elementRef.nativeElement.setAttribute('aria-describedby', `${controlName}-error`);
}

if (statusChange === 'VALID') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class DateControlsComponent implements ControlValueAccessor, OnInit, OnDe
controlContainer = inject(ControlContainer);

mode = input<Format>('yyyy-mm-dd');
formControlName = input.required<string>();

form = this.fb.group({
year: this.fb.nonNullable.control<null | number>(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ <h1 id="techRecord_adrDetails_permittedDangerousGoods-label">Permitted dangerous
<div *ngFor="let option of permittedDangerousGoodsOptions; let i = index">
<input
id="techRecord_adrDetails_permittedDangerousGoods-{{ option.value }}-checkbox"
formControlName="techRecord_adrDetails_permittedDangerousGoods-{{ option.value }}"
type="checkbox"
govukCheckbox
[checked]="form.get('techRecord_adrDetails_permittedDangerousGoods')?.value?.includes(option.value.toString())"
Expand Down Expand Up @@ -236,7 +235,6 @@ <h1 id="techRecord_adrDetails_additionalNotes_number-label">Guidance notes</h1>
<div *ngFor="let option of guidanceNotesOptions">
<input
id="techRecord_adrDetails_additionalNotes_number-{{ option.value }}-checkbox"
formControlName="techRecord_adrDetails_additionalNotes_number-{{ option.value }}"
type="checkbox"
govukCheckbox
[checked]="form.get('techRecord_adrDetails_additionalNotes_number')?.value?.includes(option.value.toString())"
Expand Down Expand Up @@ -612,7 +610,6 @@ <h1 id="techRecord_adrDetails_memosApply-label">Memo 07/09 (3 month extension) c
<div *ngFor="let option of memosApplyOptions; let i = index">
<input
id="techRecord_adrDetails_memosApply-{{ option.value }}-checkbox"
formControlName="techRecord_adrDetails_memosApply-{{ option.value }}"
type="checkbox"
govukCheckbox
[checked]="form.get('techRecord_adrDetails_memosApply')?.value?.includes(option.value.toString())"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
const control = this.form.get(formControlName);
if (!control) return;

if (control.value === null) {
if (!control.value) {
return control.setValue([value]);
}

Expand Down

0 comments on commit fa8fb74

Please sign in to comment.