60
rated 0 times
[
61]
[
1]
/ answers: 1 / hits: 22248
/ 8 Years ago, wed, december 7, 2016, 12:00:00
I'm trying to create a contact form. The form looks like this:
<form novalidate [formGroup]=contact (ngSubmit)=send()>
<p>
<label>Name
<br>
<input type=text class=input value= formControlName=name>
<span class=error>Enter your name</span>
</label>
</p>
<p>
<label>E-mail
<br>
<input type=email class=input value= formControlName=email>
<span class=error>It looks like this email is invalid</span>
</label>
</p>
<p>
<label>Phone
<br>
<input type=text class=input value= formControlName=telefone>
<span class=error>It looks like this phone number is invalid</span>
</label>
</p>
<p>
<label>Message
<br>
<textarea type=text class=input value= formControlName=message></textarea>
<span class=error>The message can't be empty</span>
</label>
</p>
<p class=submit>
<input type=submit name=submit class=bt value=Send>
</p>
</form>
In this form only the message and the name and email or the phone number fields should be required.
I'm using a formBuilder
class, so here's the TypeScript code:
this.contact = this.formBuilder.group({
name: ['', Validators.required],
email: ['', Validators.compose([/*Use custom validador??*/])],
phone: ['', Validators.compose([/*Use custom validador??*/]],
message: ['', Validators.required]
});
I tried using custom validators as a solution, but I could not figure out a solution. Any suggestions?
More From » html