I have a bank loan application which consists of alot of input fields, some of which are hidden (the hidden fields are shown dynamically based on a set of contidions). E.g if you choose option 1, a hidden field gets shown, and some other fields are hidden. If you choose option 2, some fields gets show, other fields get hidden. In the end of the form i have a which means the button will be disabled until the whole form is valid, but my problem now is that the hidden fields also get validated so the form will never be valid. Is there a way to tell angular to not validate fields if they are hidden?
The way i hide my fields is like the example below:
<form [formGroup]="form">
<select formControlName="loanType">
<option value="0">Car loan</option>
<option value="1">Student loan</option>
</select>
<div *ngIf="loanType === 0">
<input type="text" required>
</div>
<div *ngIf="loanType === 1">
<input type="text" required>
</div>
<button type="submit" [disabled]="!form.isValid">
</form>
*ngIf, you're actually removing them from the DOM.)*ngIf, yes, so it should not affect the form in any way! Weird if it does. Interestingly enough, in Angular 1, a form is correctly.$valid, even if arequiredinput withng-show="false"is empty.