Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): apply touch, dirty and pristine form control classes #24558

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ export class ValueAccessor implements ControlValueAccessor, AfterViewInit, OnDes
if (formControl) {
const methodsToPatch = ['markAsTouched', 'markAllAsTouched', 'markAsUntouched', 'markAsDirty', 'markAsPristine'];
methodsToPatch.forEach((method) => {
if (formControl.get(method)) {
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
const oldFn = formControl[method].bind(formControl);
formControl[method] = (...params: any[]) => {
oldFn(...params);
setIonicClasses(this.el);
};
}
const oldFn = formControl[method].bind(formControl);
formControl[method] = (...params: any[]) => {
oldFn(...params);
setIonicClasses(this.el);
};
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions angular/test/test-app/e2e/src/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ describe('Form', () => {
cy.get('#input-touched').click();
cy.get('#touched-input-test').should('have.class', 'ion-touched');
});

describe('markAllAsTouched', () => {
it('should apply .ion-touched to nearest ion-item', () => {
cy.get('#mark-all-touched-button').click();
cy.get('form ion-item').each(item => {
cy.wrap(item).should('have.class', 'ion-touched');
});
});
});

});

describe('change', () => {
Expand Down
4 changes: 3 additions & 1 deletion angular/test/test-app/src/app/form/form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

<ion-item>
<ion-label>DateTime</ion-label>
<ion-datetime formControlName="datetime" min="1994-03-14" max="2017-12-09" display-format="MM/DD/YYYY"></ion-datetime>
<ion-datetime formControlName="datetime" min="1994-03-14" max="2017-12-09" display-format="MM/DD/YYYY">
</ion-datetime>
</ion-item>

<ion-item>
Expand Down Expand Up @@ -65,6 +66,7 @@
<p>
Form Submit: <span id="submit">{{submitted}}</span>
</p>
<ion-button id="mark-all-touched-button" (click)="markAllAsTouched()">Mark all as touched</ion-button>
<ion-button id="submit-button" type="submit" [disabled]="!profileForm.valid">Submit</ion-button>

</form>
Expand Down
4 changes: 4 additions & 0 deletions angular/test/test-app/src/app/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export class FormComponent {
});
}

markAllAsTouched() {
this.profileForm.markAllAsTouched();
}

}