Skip to content

Commit 2d0cf45

Browse files
authored
fix(pruefi-input): fix prüfi input on ahb landing page (#477)
fix prüfi input on ahb landing page
1 parent 235776b commit 2d0cf45

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/app/features/ahbs/components/pruefi-input/pruefi-input.component.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,39 @@ export class PruefiInputComponent implements ControlValueAccessor {
122122
// Update the form control with just the pruefidentifikator
123123
if (pruefidentifikator) {
124124
this.control.setValue(pruefidentifikator, { emitEvent: false });
125+
// Emit changes immediately for dropdown selection
126+
if (this.onChange) {
127+
this.onChange(pruefidentifikator);
128+
}
125129
}
126130
} else if (digitOnlyPattern.test(inputValue)) {
127131
// Handle numeric input
128132
if (inputValue.length === 5) {
129-
// Exactly 5 digits
133+
// Exactly 5 digits - trigger immediate load
130134
pruefidentifikator = inputValue;
135+
// Update the form control with the 5 digits
136+
this.control.setValue(pruefidentifikator, { emitEvent: false });
137+
// Emit changes immediately for 5-digit input
138+
if (this.onChange) {
139+
this.onChange(pruefidentifikator);
140+
}
131141
} else if (inputValue.length > 5) {
132142
// More than 5 digits - take first 5
133143
pruefidentifikator = inputValue.slice(0, 5);
134144
// Update the form control with just the first 5 digits
135145
this.control.setValue(pruefidentifikator, { emitEvent: false });
146+
// Emit changes immediately
147+
if (this.onChange) {
148+
this.onChange(pruefidentifikator);
149+
}
136150
}
137151
// Less than 5 digits - treat as invalid (pruefidentifikator remains null)
138152
}
139153
// Any other format is considered invalid (pruefidentifikator remains null)
140154

141-
// Emit changes
142-
if (this.onChange) {
143-
this.onChange(pruefidentifikator);
155+
// Emit null for invalid input
156+
if (!pruefidentifikator && this.onChange) {
157+
this.onChange(null);
144158
}
145159
}
146160
}

src/app/features/ahbs/views/ahb-landing-page/ahb-landing-page.component.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
class="flex-1 hidden md:inline"
66
[formatVersion]="form.controls.formatVersion.value"
77
[pruefi]="form.controls.pruefi.value"
8-
(formatVersionChange)="form.controls.formatVersion.setValue($event); onClickSubmit()" />
8+
(formatVersionChange)="form.controls.formatVersion.setValue($event)"
9+
(pruefiChange)="form.controls.pruefi.setValue($event); onClickSubmit()" />
910
<app-input-search-enhanced
1011
class="inline-block w-full md:w-96 pointer-events-none opacity-50"
1112
[searchQuery]="''"

src/app/features/ahbs/views/ahb-landing-page/ahb-landing-page.component.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ export class AhbLandingPageComponent {
3636
pruefi: new FormControl<string>('', { nonNullable: true, validators: [Validators.required] }),
3737
});
3838

39-
constructor(private readonly router: Router) {}
39+
constructor(private readonly router: Router) {
40+
// Subscribe to pruefi value changes
41+
this.form.controls.pruefi.valueChanges.subscribe(value => {
42+
// If we have a 5-digit number and a format version, navigate immediately
43+
if (value?.match(/^\d{5}$/) && this.form.controls.formatVersion.value) {
44+
this.onClickSubmit();
45+
}
46+
});
47+
}
4048

4149
onClickSubmit() {
4250
if (!this.form.valid) {

0 commit comments

Comments
 (0)