Only some HTMLElements support the constraint validation api (e.g., HTMLButtonElement). I want to create a custom web component, which also supports the constraint validation api.
In the following an example is given for the desired outcome:
<form>
<input name="title" required>
<custom-form-component></custom-form-component>
</form>
<script>
const form = document.querySelector('form');
form.checkValidity();
</script>
The custom-form-component
could call setCustomValidity
on itself (based on the respective user input context) and validate itself true or false. Thus, the call on the form.checkValidity()
should return true or false with respect to the outcome of the custom-form-component
.
As I found from documentaion (e.g. on MDN) only for some element it is possible to attach a shadow root. It is not possible for form elements. However, only form elements suport the constraint validation api.
concrete question: How can I realise a custom web component, which supports constraint validation api?