diff --git a/angular/src/directives/control-value-accessors/value-accessor.ts b/angular/src/directives/control-value-accessors/value-accessor.ts index c917955fd3a..daa4a726852 100644 --- a/angular/src/directives/control-value-accessors/value-accessor.ts +++ b/angular/src/directives/control-value-accessors/value-accessor.ts @@ -96,7 +96,7 @@ export class ValueAccessor implements ControlValueAccessor, AfterViewInit, OnDes if (formControl) { const methodsToPatch = ['markAsTouched', 'markAllAsTouched', 'markAsUntouched', 'markAsDirty', 'markAsPristine']; methodsToPatch.forEach((method) => { - if (formControl.get(method)) { + if (typeof formControl[method] !== 'undefined') { const oldFn = formControl[method].bind(formControl); formControl[method] = (...params: any[]) => { oldFn(...params); diff --git a/angular/test/test-app/e2e/src/form.spec.ts b/angular/test/test-app/e2e/src/form.spec.ts index 9c0f21d4908..cc3fddbd54e 100644 --- a/angular/test/test-app/e2e/src/form.spec.ts +++ b/angular/test/test-app/e2e/src/form.spec.ts @@ -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', () => { diff --git a/angular/test/test-app/src/app/form/form.component.html b/angular/test/test-app/src/app/form/form.component.html index 0de47dae90a..34740df87fe 100644 --- a/angular/test/test-app/src/app/form/form.component.html +++ b/angular/test/test-app/src/app/form/form.component.html @@ -12,7 +12,8 @@ DateTime - + + @@ -65,6 +66,7 @@

Form Submit: {{submitted}}

+ Mark all as touched Submit diff --git a/angular/test/test-app/src/app/form/form.component.ts b/angular/test/test-app/src/app/form/form.component.ts index 6f9345330b4..157bc9a1a83 100644 --- a/angular/test/test-app/src/app/form/form.component.ts +++ b/angular/test/test-app/src/app/form/form.component.ts @@ -46,4 +46,8 @@ export class FormComponent { }); } + markAllAsTouched() { + this.profileForm.markAllAsTouched(); + } + }