refactor: form submit text as input

This commit is contained in:
2025-12-15 21:43:01 -03:00
parent a41c4a7761
commit 01ac16fbdc
3 changed files with 18 additions and 7 deletions

View File

@@ -24,7 +24,7 @@
</div>
<div class="footer">
<app-squared-btn
[text]="strings.add"
[text]="submitText()"
></app-squared-btn>
</div>
</form>

View File

@@ -5,7 +5,7 @@ import { STRINGS_INJECTOR } from '../../app.config';
import { SquaredBtn } from '../squared-btn/squared-btn';
import { NameAndCompanyFieldsErrorsDictionary } from '../../errors-dictionaries/name-and-company-field';
import { PhoneFieldErroresDictionary } from '../../errors-dictionaries/phone-field';
import { UpperfirstPipe } from "../../pipes/upperfirst-pipe";
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
import { ContactDTO } from '../../models/ContactDTO';
import { ContactFormValue } from '../../types/ContactFormValue.type';
import { FormGroupContact } from '../../utils/form-group-contact';
@@ -19,13 +19,21 @@ import { FormGroupContact } from '../../utils/form-group-contact';
export class ContactForm {
contact = output<ContactDTO>();
form = input(new FormGroupContact());
submitText = input('');
protected strings = inject(STRINGS_INJECTOR);
protected companyAndNameErrorsDictionary = new NameAndCompanyFieldsErrorsDictionary().getDictionary();
protected companyAndNameErrorsDictionary =
new NameAndCompanyFieldsErrorsDictionary().getDictionary();
protected phoneErrorsDictionary = new PhoneFieldErroresDictionary().getDictionary();
handleSubmit(contactForm: ContactFormValue) {
if(contactForm.company === null || contactForm.name === null || contactForm.phone === null) return;
const contact = new ContactDTO(undefined, contactForm.name, contactForm.company, contactForm.phone);
if (contactForm.company === null || contactForm.name === null || contactForm.phone === null)
return;
const contact = new ContactDTO(
undefined,
contactForm.name,
contactForm.company,
contactForm.phone
);
this.contact.emit(contact);
this.form().reset();
}