
FetchIt
Lightweight component for form handling and submission using Fetch API


Below is a list of FetchIt instance properties and methods.
Clears all form errors.
function (): undefineddocument.addEventListener('fetchit:after', (e) => {
e.preventDefault();
const { fetchit } = e.detail;
fetchit.clearErrors();
});Clears errors for a specific field.
function (name: string): objectdocument.addEventListener('fetchit:after', (e) => {
e.preventDefault();
const { fetchit } = e.detail;
const { fields, errors, customErrors } = fetchit.clearError('password');
});Marks a field as invalid by name and sets its error message. Useful when integrating front-end validation.
function (name: string, message: string): undefineddocument.addEventListener('fetchit:before', (e) => {
e.preventDefault();
const { fetchit } = e.detail;
// Field validation
fetchit.setError('email', 'Email validation failed');
});Important!
Client-side validation is not secure and should only be used to improve user experience.
Disables all form elements.
function (): undefinedRemoves disabled from all form elements.
function (): undefinedReturns an array of elements for the given field name.
function (name: string): HTMLElement[]