@@ -129,12 +129,15 @@ export const formResetCallback = (event: Event) => {
129
129
/** Get the Set of elements attached to this form */
130
130
const elements = formElementsMap . get ( event . target as HTMLFormElement ) ;
131
131
132
- /** Loop over the elements and call formResetCallback if applicable */
133
- elements . forEach ( element => {
134
- if ( ( element . constructor as any ) . formAssociated && element . formResetCallback ) {
135
- element . formResetCallback . apply ( element ) ;
136
- }
137
- } ) ;
132
+ /** Some forms won't contain form associated custom elements */
133
+ if ( elements && elements . size ) {
134
+ /** Loop over the elements and call formResetCallback if applicable */
135
+ elements . forEach ( element => {
136
+ if ( ( element . constructor as any ) . formAssociated && element . formResetCallback ) {
137
+ element . formResetCallback . apply ( element ) ;
138
+ }
139
+ } ) ;
140
+ }
138
141
} ;
139
142
140
143
/**
@@ -213,13 +216,17 @@ export const throwIfNotFormAssociated = (ref: ICustomElement, message: string, E
213
216
*/
214
217
export const overrideFormMethod = ( form : HTMLFormElement , returnValue : boolean , method : 'checkValidity' | 'reportValidity' ) : boolean => {
215
218
const elements = formElementsMap . get ( form ) ;
216
- elements . forEach ( element => {
217
- const internals = internalsMap . get ( element ) ;
218
- const valid = internals [ method ] ( ) ;
219
- if ( ! valid ) {
220
- returnValue = false ;
221
- }
222
- } ) ;
219
+
220
+ /** Some forms won't contain form associated custom elements */
221
+ if ( elements && elements . size ) {
222
+ elements . forEach ( element => {
223
+ const internals = internalsMap . get ( element ) ;
224
+ const valid = internals [ method ] ( ) ;
225
+ if ( ! valid ) {
226
+ returnValue = false ;
227
+ }
228
+ } ) ;
229
+ }
223
230
return returnValue ;
224
231
} ;
225
232
0 commit comments