|
| 1 | +<ion-header> |
| 2 | + <ion-toolbar> |
| 3 | + <ion-title>Template-Driven Form Validation Test</ion-title> |
| 4 | + </ion-toolbar> |
| 5 | +</ion-header> |
| 6 | + |
| 7 | +<ion-content> |
| 8 | + <form #templateForm="ngForm" (ngSubmit)="onSubmit(templateForm)"> |
| 9 | + <ion-list> |
| 10 | + <!-- Test ion-input with required validation --> |
| 11 | + <ion-item> |
| 12 | + <ion-input |
| 13 | + label="Required Input" |
| 14 | + [(ngModel)]="inputValue" |
| 15 | + name="inputField" |
| 16 | + required |
| 17 | + #inputField="ngModel" |
| 18 | + id="template-input-test" |
| 19 | + errorText="This field is required" |
| 20 | + helperText="Enter some text"> |
| 21 | + </ion-input> |
| 22 | + </ion-item> |
| 23 | + |
| 24 | + <!-- Display validation state for debugging --> |
| 25 | + <ion-item> |
| 26 | + <ion-label> |
| 27 | + <p>Input Touched: <span id="input-touched">{{inputField.touched}}</span></p> |
| 28 | + <p>Input Invalid: <span id="input-invalid">{{inputField.invalid}}</span></p> |
| 29 | + <p>Input Errors: <span id="input-errors">{{inputField.errors | json}}</span></p> |
| 30 | + </ion-label> |
| 31 | + </ion-item> |
| 32 | + |
| 33 | + <!-- Test ion-textarea with required validation --> |
| 34 | + <ion-item> |
| 35 | + <ion-textarea |
| 36 | + label="Required Textarea" |
| 37 | + [(ngModel)]="textareaValue" |
| 38 | + name="textareaField" |
| 39 | + required |
| 40 | + #textareaField="ngModel" |
| 41 | + id="template-textarea-test" |
| 42 | + errorText="This field is required" |
| 43 | + helperText="Enter some text" |
| 44 | + rows="4"> |
| 45 | + </ion-textarea> |
| 46 | + </ion-item> |
| 47 | + |
| 48 | + <!-- Display validation state for debugging --> |
| 49 | + <ion-item> |
| 50 | + <ion-label> |
| 51 | + <p>Textarea Touched: <span id="textarea-touched">{{textareaField.touched}}</span></p> |
| 52 | + <p>Textarea Invalid: <span id="textarea-invalid">{{textareaField.invalid}}</span></p> |
| 53 | + <p>Textarea Errors: <span id="textarea-errors">{{textareaField.errors | json}}</span></p> |
| 54 | + </ion-label> |
| 55 | + </ion-item> |
| 56 | + |
| 57 | + <!-- Additional test with minlength validation --> |
| 58 | + <ion-item> |
| 59 | + <ion-input |
| 60 | + label="Min Length Input (3 chars)" |
| 61 | + [(ngModel)]="minLengthValue" |
| 62 | + name="minLengthField" |
| 63 | + required |
| 64 | + minlength="3" |
| 65 | + #minLengthField="ngModel" |
| 66 | + id="template-minlength-test" |
| 67 | + errorText="Minimum 3 characters required" |
| 68 | + helperText="Enter at least 3 characters"> |
| 69 | + </ion-input> |
| 70 | + </ion-item> |
| 71 | + |
| 72 | + <!-- Display validation state for minlength field --> |
| 73 | + <ion-item> |
| 74 | + <ion-label> |
| 75 | + <p>MinLength Touched: <span id="minlength-touched">{{minLengthField.touched}}</span></p> |
| 76 | + <p>MinLength Invalid: <span id="minlength-invalid">{{minLengthField.invalid}}</span></p> |
| 77 | + <p>MinLength Errors: <span id="minlength-errors">{{minLengthField.errors | json}}</span></p> |
| 78 | + </ion-label> |
| 79 | + </ion-item> |
| 80 | + </ion-list> |
| 81 | + |
| 82 | + <div class="ion-padding"> |
| 83 | + <p>Form Valid: <span id="form-valid">{{templateForm.valid}}</span></p> |
| 84 | + <p>Form Submitted: <span id="form-submitted">{{submitted}}</span></p> |
| 85 | + |
| 86 | + <ion-button type="submit" id="submit-button" [disabled]="!templateForm.valid"> |
| 87 | + Submit Form |
| 88 | + </ion-button> |
| 89 | + |
| 90 | + <ion-button type="button" id="reset-button" (click)="resetForm(templateForm)"> |
| 91 | + Reset Form |
| 92 | + </ion-button> |
| 93 | + |
| 94 | + <ion-button type="button" id="touch-all-button" (click)="templateForm.form.markAllAsTouched()"> |
| 95 | + Mark All as Touched |
| 96 | + </ion-button> |
| 97 | + </div> |
| 98 | + |
| 99 | + <div class="ion-padding"> |
| 100 | + <h3>Form Values:</h3> |
| 101 | + <pre id="form-values">{{templateForm.value | json}}</pre> |
| 102 | + </div> |
| 103 | + </form> |
| 104 | + |
| 105 | + <div class="ion-padding"> |
| 106 | + <h3>Instructions to reproduce issue:</h3> |
| 107 | + <ol> |
| 108 | + <li>Click in the "Required Input" field</li> |
| 109 | + <li>Click outside without entering text</li> |
| 110 | + <li>The field should show as touched and invalid</li> |
| 111 | + <li>The error text should appear below the input</li> |
| 112 | + <li>For screen readers, the validation state should be announced</li> |
| 113 | + </ol> |
| 114 | + <p><strong>Note:</strong> With template-driven forms, Angular applies validation classes to the wrapper element, not directly to ion-input/ion-textarea.</p> |
| 115 | + </div> |
| 116 | +</ion-content> |
0 commit comments