0
Take a good look at the form
<form #registerForm="ngForm" (ngSubmit)="onSubmit(registerForm)" class="col-lg-10" >
<p>
<label >Nome</label>
<input type="text" name="name" #name="ngModel" [(ngModel)]="user.name" class="form-control" required/>
<span *ngIf="!name.valid && name.touched">
O nome é obrigatório
</span>
</p>
<p>
<label >Sobrenome</label>
<input type="text" name="surname" #surname="ngModel" [(ngModel)]="user.surname" class="form-control" required/>
<span *ngIf="!surname.valid && surname.touched">
O sobrenome é obrigatório
</span>
</p>
<p>
<label >Email</label>
<input type="text" name="email" #email="ngModel" [(ngModel)]="user.email" class="form-control" required/>
<span *ngIf="!email.valid && email.touched">
O email é obrigatório
</span>
</p>
<p>
<label>Senha</label>
<input type="text" name="password" #password="ngModel" [(ngModel)]="user.password" class="form-control" required/>
<span *ngIf="!password.valid && password.touched">
A senha é obrigatório
</span>
</p>
<input type="submit" value="{{title}}" class="btn btn-primary" [disabled]="!registerForm.form.valid" />
</form>
</div>
Why would the button registration was not disabled?
To know the value of !registerForm.form.Valid if it is true or false I did the following ...
In the component file I put so;
onSubmit(form: NgForm) {
console.log(form);
}
And I checked on the console how I’d be if I was like this;
And I submitted the form and it gave this;
The attribute Valid was as true knowing you should be like false
I wonder where it’s wrong?
checked whether the condition
registerForm.form.valid
is returningfalse
?– Leandro Angelo
how do I know?
– wladyband
if I leave so it gets disabled registerForm.form.Valid but if I leave so it is enabled ! registerForm.form.Valid
– wladyband
will need some module to install?
– wladyband
this page is in error, already repair?
– wladyband
sorry the page is not in error, I copied and pasted your suggestion in my project and did not work.
– wladyband
There is nothing wrong with your form, see: https://stackblitz.com/edit/angular-p8jtmw?file=src%2Fapp%2Fapp.component.html
– Marconi
What I would indicate is to check for something in your console with error.
– Marconi
there is no error in the consoles
– wladyband
i did an update of the post, could take a look please?
– wladyband
@wladyband you have the variable
user
defined in hists
?– Marconi
I have yes, he is in my project
– wladyband
How strange I did tests onlline and everything works.
– Marconi
@Marconi could take a look, this is my project https://github.com/wladyband/epui
– wladyband
https://github.com/wladyband/epui/blob/master/src/app/registro/registro/registro.component.html
– wladyband
Let’s go continue this discussion in chat.
– Marconi
Please avoid long discussions in the comments; your talk was moved to the chat
– rray