refactor: form submit text as input
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<app-squared-btn
|
<app-squared-btn
|
||||||
[text]="strings.add"
|
[text]="submitText()"
|
||||||
></app-squared-btn>
|
></app-squared-btn>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -5,7 +5,7 @@ import { STRINGS_INJECTOR } from '../../app.config';
|
|||||||
import { SquaredBtn } from '../squared-btn/squared-btn';
|
import { SquaredBtn } from '../squared-btn/squared-btn';
|
||||||
import { NameAndCompanyFieldsErrorsDictionary } from '../../errors-dictionaries/name-and-company-field';
|
import { NameAndCompanyFieldsErrorsDictionary } from '../../errors-dictionaries/name-and-company-field';
|
||||||
import { PhoneFieldErroresDictionary } from '../../errors-dictionaries/phone-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 { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { ContactFormValue } from '../../types/ContactFormValue.type';
|
import { ContactFormValue } from '../../types/ContactFormValue.type';
|
||||||
import { FormGroupContact } from '../../utils/form-group-contact';
|
import { FormGroupContact } from '../../utils/form-group-contact';
|
||||||
@@ -19,13 +19,21 @@ import { FormGroupContact } from '../../utils/form-group-contact';
|
|||||||
export class ContactForm {
|
export class ContactForm {
|
||||||
contact = output<ContactDTO>();
|
contact = output<ContactDTO>();
|
||||||
form = input(new FormGroupContact());
|
form = input(new FormGroupContact());
|
||||||
|
submitText = input('');
|
||||||
protected strings = inject(STRINGS_INJECTOR);
|
protected strings = inject(STRINGS_INJECTOR);
|
||||||
protected companyAndNameErrorsDictionary = new NameAndCompanyFieldsErrorsDictionary().getDictionary();
|
protected companyAndNameErrorsDictionary =
|
||||||
|
new NameAndCompanyFieldsErrorsDictionary().getDictionary();
|
||||||
protected phoneErrorsDictionary = new PhoneFieldErroresDictionary().getDictionary();
|
protected phoneErrorsDictionary = new PhoneFieldErroresDictionary().getDictionary();
|
||||||
|
|
||||||
handleSubmit(contactForm: ContactFormValue) {
|
handleSubmit(contactForm: ContactFormValue) {
|
||||||
if(contactForm.company === null || contactForm.name === null || contactForm.phone === null) return;
|
if (contactForm.company === null || contactForm.name === null || contactForm.phone === null)
|
||||||
const contact = new ContactDTO(undefined, contactForm.name, contactForm.company, contactForm.phone);
|
return;
|
||||||
|
const contact = new ContactDTO(
|
||||||
|
undefined,
|
||||||
|
contactForm.name,
|
||||||
|
contactForm.company,
|
||||||
|
contactForm.phone
|
||||||
|
);
|
||||||
this.contact.emit(contact);
|
this.contact.emit(contact);
|
||||||
this.form().reset();
|
this.form().reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
<app-main-header [title]="strings.contactList"/>
|
<app-main-header [title]="strings.contactList"/>
|
||||||
<app-card bgColor="var(--secondary)">
|
<app-card bgColor="var(--secondary)">
|
||||||
<app-contact-form class="form" (contact)="save($event)">
|
<app-contact-form
|
||||||
<app-form-header
|
(contact)="save($event)"
|
||||||
|
[submitText]="strings.add"
|
||||||
|
class="form"
|
||||||
|
><app-form-header
|
||||||
[subtitle]="strings.allFieldRequired|upperfirst"
|
[subtitle]="strings.allFieldRequired|upperfirst"
|
||||||
[title]="strings.addContact|upperfirst"
|
[title]="strings.addContact|upperfirst"
|
||||||
slot="header"
|
slot="header"
|
||||||
|
|||||||
Reference in New Issue
Block a user