Skip to content

Commit

Permalink
More defensive refs
Browse files Browse the repository at this point in the history
  • Loading branch information
smikhalevski committed Nov 11, 2023
1 parent ef8a131 commit dba01ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ export function constraintValidationPlugin(): PluginInjector<ConstraintValidatio
field.element.removeEventListener('invalid', changeListener);
}

field.element = element;

const events: Event[] = [];

if (isValidatable(element)) {
Expand All @@ -154,11 +152,14 @@ export function constraintValidationPlugin(): PluginInjector<ConstraintValidatio
element.addEventListener('change', changeListener);
element.addEventListener('invalid', changeListener);

field.element = element;
field.validity = element.validity;

setError(field, element.validationMessage, 1, events);
} else {
field.element = field.validity = null;

// Delete the associated constraint error
field.validity = null;
deleteError(field, 1, events);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function scrollToErrorPlugin(): PluginInjector<ScrollToErrorPlugin> {
const { ref } = field;

field.ref = element => {
field.element = element;
field.element = element instanceof Element ? element : null;
ref?.(element);
};

Expand Down

0 comments on commit dba01ff

Please sign in to comment.