refactor: form field validation dict to signal for multilang

This commit is contained in:
2025-12-24 22:19:25 -03:00
parent 10f9b77807
commit 10dd04dad7
9 changed files with 36 additions and 25 deletions

View File

@@ -3,19 +3,19 @@
<div class="fields">
<app-form-field
[errorsDictionary]="companyAndNameErrorsDictionary"
[errorsDictionary]="companyAndNameErrorsDictionary()"
formControlName="name"
[label]="(languageManager.strings.name|upperfirst) + ':'"
[placeholder]="languageManager.strings.contactsName|upperfirst"
/>
<app-form-field
[errorsDictionary]="companyAndNameErrorsDictionary"
[errorsDictionary]="companyAndNameErrorsDictionary()"
formControlName="company"
[label]="(languageManager.strings.company|upperfirst) + ':'"
[placeholder]="languageManager.strings.contactsCompany|upperfirst"
/>
<app-form-field
[errorsDictionary]="phoneErrorsDictionary"
[errorsDictionary]="phoneErrorsDictionary()"
formControlName="phone"
[label]="(languageManager.strings.phone|upperfirst) +':'"
[placeholder]="languageManager.strings.contactsPhone|upperfirst"

View File

@@ -12,7 +12,10 @@ describe('ContactForm', () => {
let languageManager: jasmine.SpyObj<LanguageManager>;
beforeEach(async () => {
languageManager = jasmine.createSpyObj(LanguageManager.name, [], { strings: strings.en });
languageManager = jasmine.createSpyObj(LanguageManager.name, [], {
strings: strings.en,
selectedLanguage$: () => 'en',
});
await TestBed.configureTestingModule({
imports: [ContactForm],

View File

@@ -12,7 +12,7 @@
<div>
@for(error of errorsDictionary()|keyvalue; track error.key) {
@if(control.hasError(error.key) && isDirty){
<p class="error-text">• {{error.value}}</p>
<p class="error-text">• {{error.value|upperfirst}}</p>
}
}
</div>

View File

@@ -1,10 +1,11 @@
import { KeyValuePipe } from '@angular/common';
import { Component, computed, input, Optional, Self, signal } from '@angular/core';
import { ControlValueAccessor, NgControl, ReactiveFormsModule } from '@angular/forms';
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
@Component({
selector: 'app-form-field',
imports: [ReactiveFormsModule, KeyValuePipe],
imports: [ReactiveFormsModule, KeyValuePipe, UpperfirstPipe],
templateUrl: './form-field.html',
styleUrl: './form-field.scss',
})