refactor: form submit text as input
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
</div>
|
||||
<div class="footer">
|
||||
<app-squared-btn
|
||||
[text]="strings.add"
|
||||
[text]="submitText()"
|
||||
></app-squared-btn>
|
||||
</div>
|
||||
</form>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<app-main-header [title]="strings.contactList"/>
|
||||
<app-card bgColor="var(--secondary)">
|
||||
<app-contact-form class="form" (contact)="save($event)">
|
||||
<app-form-header
|
||||
<app-contact-form
|
||||
(contact)="save($event)"
|
||||
[submitText]="strings.add"
|
||||
class="form"
|
||||
><app-form-header
|
||||
[subtitle]="strings.allFieldRequired|upperfirst"
|
||||
[title]="strings.addContact|upperfirst"
|
||||
slot="header"
|
||||
|
||||
Reference in New Issue
Block a user