checkValidity
can be called on a form's elements before the element has been loaded which causes an error
#1745
Labels
bug
Things that aren't working right in the library.
waiting on element internals
Issues to tackle once ElementInternals lands in all supported browsers.
Describe the bug
After the change introduced in #1708 ,
form.checkValidity()
can be called but can potentially raise an error if the function is called before the elements thatFormControlController
loops through are loaded since the element(s) can benull
.To Reproduce
form.checkValidity()
immediately after appending the Shoelace form control to the document so that the validity check is called before the element finishes loadingDemo
Here is a quick demo repo https://github.com/alianam/shoelace-bug/tree/main which includes simple setup instructions to clone the repo, install the dependencies, and then run the server. Once you open the page locally, and open the console, you will immediately see the error mentioned in this bug report.
Screenshots
Browser / OS
Additional information
As a temporary workaround, I added an async function that finds and loops over all Shoelace elements in the
document
, then it callsupdateComplete
on each of them (inspired by your docs here - thanks!), and then Iawait Promise.allSettled()
to ensure all of them have completed rendering. Only then do I proceed to callcheckValidity
and am able to avoid the error reported in this bug.While this works, it seems like this check should exist in the Shoelace code and not be a requirement for those using the form controls, which is why I've created this bug report
The text was updated successfully, but these errors were encountered: