Skip to content

Commit f2ebcda

Browse files
asyncLizcopybara-github
authored andcommitted
chore(labs): fix onReportValidity called twice with form.reportValidity
PiperOrigin-RevId: 597661314
1 parent 5c22b2b commit f2ebcda

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

labs/behaviors/on-report-validity.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,10 @@ export function mixinOnReportValidity<
201201
reportedInvalidEventFromForm = false;
202202
this.addEventListener(
203203
'invalid',
204-
(invalidEvent) => {
204+
() => {
205205
reportedInvalidEventFromForm = true;
206-
if (!invalidEvent.defaultPrevented) {
207-
this[onReportValidity](invalidEvent);
208-
}
206+
// Constructor's invalid listener will handle reporting invalid
207+
// events.
209208
},
210209
{signal: formReportValidityCleanup.signal},
211210
);

labs/behaviors/on-report-validity_test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('mixinOnReportValidity()', () => {
5858
control[onReportValidity] = jasmine.createSpy('onReportValidity');
5959

6060
control.reportValidity();
61-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
61+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
6262
});
6363
});
6464

@@ -69,7 +69,7 @@ describe('mixinOnReportValidity()', () => {
6969

7070
control.required = true;
7171
control.reportValidity();
72-
expect(control[onReportValidity]).toHaveBeenCalledWith(
72+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
7373
jasmine.any(Event),
7474
);
7575
});
@@ -101,7 +101,7 @@ describe('mixinOnReportValidity()', () => {
101101
control.checked = true;
102102
control.reportValidity();
103103

104-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
104+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
105105
});
106106
});
107107

@@ -114,7 +114,7 @@ describe('mixinOnReportValidity()', () => {
114114
form.appendChild(control);
115115

116116
form.reportValidity();
117-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
117+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
118118
});
119119

120120
it('should be called with null when form.requestSubmit() is called and it is valid', () => {
@@ -134,7 +134,7 @@ describe('mixinOnReportValidity()', () => {
134134
document.body.appendChild(form);
135135
form.requestSubmit();
136136
form.remove();
137-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
137+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
138138
});
139139

140140
it('should be called with null when form submits declaratively and it is valid', () => {
@@ -156,7 +156,7 @@ describe('mixinOnReportValidity()', () => {
156156
document.body.appendChild(form);
157157
submitButton.click();
158158
form.remove();
159-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
159+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
160160
});
161161
});
162162

@@ -169,7 +169,7 @@ describe('mixinOnReportValidity()', () => {
169169

170170
control.required = true;
171171
form.reportValidity();
172-
expect(control[onReportValidity]).toHaveBeenCalledWith(
172+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
173173
jasmine.any(Event),
174174
);
175175
});
@@ -209,7 +209,7 @@ describe('mixinOnReportValidity()', () => {
209209
control.required = true;
210210
form.requestSubmit();
211211
form.remove();
212-
expect(control[onReportValidity]).toHaveBeenCalledWith(
212+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
213213
jasmine.any(Event),
214214
);
215215
});
@@ -263,7 +263,7 @@ describe('mixinOnReportValidity()', () => {
263263
document.body.appendChild(form);
264264
submitButton.click();
265265
form.remove();
266-
expect(control[onReportValidity]).toHaveBeenCalledWith(
266+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
267267
jasmine.any(Event),
268268
);
269269
});
@@ -315,7 +315,7 @@ describe('mixinOnReportValidity()', () => {
315315
form.reportValidity();
316316
form.remove();
317317

318-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
318+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
319319
});
320320

321321
it('should be called with null when form.requestSubmit() is called after fixing invalid', () => {
@@ -345,7 +345,7 @@ describe('mixinOnReportValidity()', () => {
345345
form.requestSubmit();
346346
form.remove();
347347

348-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
348+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
349349
});
350350

351351
it('should be called with null when form submits declaratively after fixing invalid', () => {
@@ -377,7 +377,7 @@ describe('mixinOnReportValidity()', () => {
377377
submitButton.click();
378378
form.remove();
379379

380-
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
380+
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
381381
});
382382
});
383383

0 commit comments

Comments
 (0)