mirror of
https://github.com/material-components/material-web.git
synced 2024-09-11 13:46:10 +03:00
chore(labs): fix onReportValidity called twice with form.reportValidity
PiperOrigin-RevId: 597661314
This commit is contained in:
parent
5c22b2baea
commit
f2ebcdac79
@ -201,11 +201,10 @@ export function mixinOnReportValidity<
|
|||||||
reportedInvalidEventFromForm = false;
|
reportedInvalidEventFromForm = false;
|
||||||
this.addEventListener(
|
this.addEventListener(
|
||||||
'invalid',
|
'invalid',
|
||||||
(invalidEvent) => {
|
() => {
|
||||||
reportedInvalidEventFromForm = true;
|
reportedInvalidEventFromForm = true;
|
||||||
if (!invalidEvent.defaultPrevented) {
|
// Constructor's invalid listener will handle reporting invalid
|
||||||
this[onReportValidity](invalidEvent);
|
// events.
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{signal: formReportValidityCleanup.signal},
|
{signal: formReportValidityCleanup.signal},
|
||||||
);
|
);
|
||||||
|
@ -58,7 +58,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
control[onReportValidity] = jasmine.createSpy('onReportValidity');
|
control[onReportValidity] = jasmine.createSpy('onReportValidity');
|
||||||
|
|
||||||
control.reportValidity();
|
control.reportValidity();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
|
|
||||||
control.required = true;
|
control.required = true;
|
||||||
control.reportValidity();
|
control.reportValidity();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
|
||||||
jasmine.any(Event),
|
jasmine.any(Event),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -101,7 +101,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
control.checked = true;
|
control.checked = true;
|
||||||
control.reportValidity();
|
control.reportValidity();
|
||||||
|
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
form.appendChild(control);
|
form.appendChild(control);
|
||||||
|
|
||||||
form.reportValidity();
|
form.reportValidity();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called with null when form.requestSubmit() is called and it is valid', () => {
|
it('should be called with null when form.requestSubmit() is called and it is valid', () => {
|
||||||
@ -134,7 +134,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
form.requestSubmit();
|
form.requestSubmit();
|
||||||
form.remove();
|
form.remove();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called with null when form submits declaratively and it is valid', () => {
|
it('should be called with null when form submits declaratively and it is valid', () => {
|
||||||
@ -156,7 +156,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
submitButton.click();
|
submitButton.click();
|
||||||
form.remove();
|
form.remove();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
|
|
||||||
control.required = true;
|
control.required = true;
|
||||||
form.reportValidity();
|
form.reportValidity();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
|
||||||
jasmine.any(Event),
|
jasmine.any(Event),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -209,7 +209,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
control.required = true;
|
control.required = true;
|
||||||
form.requestSubmit();
|
form.requestSubmit();
|
||||||
form.remove();
|
form.remove();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
|
||||||
jasmine.any(Event),
|
jasmine.any(Event),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -263,7 +263,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
submitButton.click();
|
submitButton.click();
|
||||||
form.remove();
|
form.remove();
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(
|
||||||
jasmine.any(Event),
|
jasmine.any(Event),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -315,7 +315,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
form.reportValidity();
|
form.reportValidity();
|
||||||
form.remove();
|
form.remove();
|
||||||
|
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called with null when form.requestSubmit() is called after fixing invalid', () => {
|
it('should be called with null when form.requestSubmit() is called after fixing invalid', () => {
|
||||||
@ -345,7 +345,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
form.requestSubmit();
|
form.requestSubmit();
|
||||||
form.remove();
|
form.remove();
|
||||||
|
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called with null when form submits declaratively after fixing invalid', () => {
|
it('should be called with null when form submits declaratively after fixing invalid', () => {
|
||||||
@ -377,7 +377,7 @@ describe('mixinOnReportValidity()', () => {
|
|||||||
submitButton.click();
|
submitButton.click();
|
||||||
form.remove();
|
form.remove();
|
||||||
|
|
||||||
expect(control[onReportValidity]).toHaveBeenCalledWith(null);
|
expect(control[onReportValidity]).toHaveBeenCalledOnceWith(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user