Skip to content

Commit 1493bf7

Browse files
committed
refactor(tests, input): doing cleanup across input and tests
1 parent 7926f08 commit 1493bf7

File tree

8 files changed

+9
-112
lines changed

8 files changed

+9
-112
lines changed

core/src/components/input/input.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class Input implements ComponentInterface {
406406
/**
407407
* Checks if the input is in an invalid state based on Ionic validation classes
408408
*/
409-
private checkValidationState(): boolean {
409+
private checkInvalidState(): boolean {
410410
const hasIonTouched = this.el.classList.contains('ion-touched');
411411
const hasIonInvalid = this.el.classList.contains('ion-invalid');
412412

@@ -426,7 +426,7 @@ export class Input implements ComponentInterface {
426426
// Watch for class changes to update validation state
427427
if (Build.isBrowser && typeof MutationObserver !== 'undefined') {
428428
this.validationObserver = new MutationObserver(() => {
429-
const newIsInvalid = this.checkValidationState();
429+
const newIsInvalid = this.checkInvalidState();
430430
if (this.isInvalid !== newIsInvalid) {
431431
this.isInvalid = newIsInvalid;
432432
// Force a re-render to update aria-describedby immediately
@@ -441,7 +441,7 @@ export class Input implements ComponentInterface {
441441
}
442442

443443
// Always set initial state
444-
this.isInvalid = this.checkValidationState();
444+
this.isInvalid = this.checkInvalidState();
445445

446446
this.debounceChanged();
447447
if (Build.isBrowser) {

core/src/components/input/test/validation/index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@
3030
margin-bottom: 5px;
3131
}
3232

33-
.aria-live-region {
34-
position: absolute;
35-
left: -10000px;
36-
width: 1px;
37-
height: 1px;
38-
overflow: hidden;
39-
}
40-
4133
.validation-info {
4234
margin: 20px;
4335
padding: 10px;

core/src/components/textarea/test/validation/index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@
3030
margin-bottom: 5px;
3131
}
3232

33-
.aria-live-region {
34-
position: absolute;
35-
left: -10000px;
36-
width: 1px;
37-
height: 1px;
38-
overflow: hidden;
39-
}
40-
4133
.validation-info {
4234
margin: 20px;
4335
padding: 10px;

packages/angular/test/base/src/app/standalone/validation/input-validation/input-validation.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h2>Optional Field (No Validation)</h2>
125125
</form>
126126

127127
<div class="ion-padding">
128-
<ion-button id="submit-btn" expand="block" [disabled]="!isFormValid()" (click)="onSubmit()">Submit Form</ion-button>
129-
<ion-button id="reset-btn" expand="block" fill="outline" (click)="onReset()">Reset Form</ion-button>
128+
<ion-button id="submit-btn" expand="block" [disabled]="form.invalid" (click)="onSubmit()">Submit Form</ion-button>
129+
<ion-button id="reset-btn" expand="block" fill="outline" (click)="form.reset()">Reset Form</ion-button>
130130
</div>
131131
</ion-content>

packages/angular/test/base/src/app/standalone/validation/input-validation/input-validation.component.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import {
3131
]
3232
})
3333
export class InputValidationComponent {
34-
// Track which fields have been touched (using Set like vanilla test)
35-
touchedFields = new Set<string>();
36-
3734
// Field metadata for labels and error messages
3835
fieldMetadata = {
3936
email: {
@@ -79,47 +76,10 @@ export class InputValidationComponent {
7976

8077
constructor(private fb: FormBuilder) {}
8178

82-
// Check if a field is invalid
83-
isInvalid(fieldName: string): boolean {
84-
const control = this.form.get(fieldName);
85-
return !!(control && control.invalid && control.touched);
86-
}
87-
88-
// Check if a field is valid
89-
isValid(fieldName: string): boolean {
90-
const control = this.form.get(fieldName);
91-
return !!(control && control.valid && control.touched);
92-
}
93-
94-
95-
// Check if form is valid (excluding optional field)
96-
isFormValid(): boolean {
97-
const requiredFields = ['email', 'name', 'phone', 'password', 'age'];
98-
return requiredFields.every(field => {
99-
const control = this.form.get(field);
100-
return control && control.valid;
101-
});
102-
}
103-
10479
// Submit form
10580
onSubmit(): void {
106-
if (this.isFormValid()) {
81+
if (this.form.valid) {
10782
alert('Form submitted successfully!');
10883
}
10984
}
110-
111-
// Reset form
112-
onReset(): void {
113-
// Reset form values
114-
this.form.reset();
115-
116-
// Clear touched fields
117-
this.touchedFields.clear();
118-
119-
// Remove validation classes from all inputs
120-
const inputs = document.querySelectorAll('ion-input');
121-
inputs.forEach(input => {
122-
input.classList.remove('ion-valid', 'ion-invalid', 'ion-touched');
123-
});
124-
}
12585
}

packages/angular/test/base/src/app/standalone/validation/textarea-validation/textarea-validation.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ <h2>Optional Notes</h2>
127127
</form>
128128

129129
<div class="ion-padding">
130-
<ion-button id="submit-btn" expand="block" [disabled]="!isFormValid()" (click)="onSubmit()">Submit Form</ion-button>
131-
<ion-button id="reset-btn" expand="block" fill="outline" (click)="onReset()">Reset Form</ion-button>
130+
<ion-button id="submit-btn" expand="block" [disabled]="form.invalid" (click)="onSubmit()">Submit Form</ion-button>
131+
<ion-button id="reset-btn" expand="block" fill="outline" (click)="form.reset()">Reset Form</ion-button>
132132
</div>
133133
</ion-content>

packages/angular/test/base/src/app/standalone/validation/textarea-validation/textarea-validation.component.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ h2 {
1313
margin-bottom: 5px;
1414
}
1515

16-
.aria-live-region {
17-
position: absolute;
18-
left: -10000px;
19-
width: 1px;
20-
height: 1px;
21-
overflow: hidden;
22-
}
23-
2416
.validation-info {
2517
margin: 20px;
2618
padding: 10px;

packages/angular/test/base/src/app/standalone/validation/textarea-validation/textarea-validation.component.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ function addressValidator(control: AbstractControl): ValidationErrors | null {
4343
]
4444
})
4545
export class TextareaValidationComponent {
46-
// Track which fields have been touched (using Set like vanilla test)
47-
touchedFields = new Set<string>();
48-
4946
// Field metadata for labels and error messages
5047
fieldMetadata = {
5148
description: {
@@ -99,46 +96,10 @@ export class TextareaValidationComponent {
9996

10097
constructor(private fb: FormBuilder) {}
10198

102-
// Check if a field is invalid
103-
isInvalid(fieldName: string): boolean {
104-
const control = this.form.get(fieldName);
105-
return !!(control && control.invalid && control.touched);
106-
}
107-
108-
// Check if a field is valid
109-
isValid(fieldName: string): boolean {
110-
const control = this.form.get(fieldName);
111-
return !!(control && control.valid && control.touched);
112-
}
113-
114-
// Check if form is valid (excluding optional field)
115-
isFormValid(): boolean {
116-
const requiredFields = ['description', 'comments', 'bio', 'address', 'review'];
117-
return requiredFields.every(field => {
118-
const control = this.form.get(field);
119-
return control && control.valid;
120-
});
121-
}
122-
12399
// Submit form
124100
onSubmit(): void {
125-
if (this.isFormValid()) {
101+
if (this.form.valid) {
126102
alert('Form submitted successfully!');
127103
}
128104
}
129-
130-
// Reset form
131-
onReset(): void {
132-
// Reset form values
133-
this.form.reset();
134-
135-
// Clear touched fields
136-
this.touchedFields.clear();
137-
138-
// Remove validation classes from all textareas
139-
const textareas = document.querySelectorAll('ion-textarea');
140-
textareas.forEach(textarea => {
141-
textarea.classList.remove('ion-valid', 'ion-invalid', 'ion-touched');
142-
});
143-
}
144105
}

0 commit comments

Comments
 (0)