astro-reactive-form/packages/validator/Validator.astro
Ayo Ayco 4dc020027f
feat: create astro reactive validator (#90)
* feat: initial validator component

* chore: fix eslint for validator

* chore: update package info for validator

* chore: remove vscode settings for docs

* chore: put docs and demo into apps

* chore: move package scope @astro-reactive

* test: update tests for validator

* feat: validator functions, hooks

* feat: validator sets haserrors attribute

* feat: use data-validator attributes

* feat: showValidationHints

* feature: add logic for all validators

* refactor: remove Validator component usage

* docs(validator): initial readme

* chore: comment out unsupported validator

* docs(validator): update installation

* chore: package docs and publish

* chore: update deps

* docs: update npm info on docs

* docs(validator): update docs for validator

* fix(form): handle undefined form

* test(validator): update tests

* chore: organize files; update deps

* chore: fix build scripts
2022-10-15 16:32:02 +02:00

35 lines
993 B
Text

---
import type { HookType } from './core';
export interface Props {
hook?: HookType;
displayErrorMessages?: boolean;
}
const { hook = 'all', displayErrorMessages = false } = Astro.props;
---
<input hidden name="hook" id="hook" value={hook} />
<input
hidden
name="displayErrorMessages"
id="displayErrorMessages"
value={displayErrorMessages.toString()}
/>
<script>
// TODO: selectors should by unique IDs generated by our library
// TODO: implement type guards pls 😱
// TODO: create deserializer util
// TODO: handle hooks / when to attach event listeners
// const form = document.querySelector('form');
import { clearErrors, validate } from './core';
// const hook: HookType = (document.getElementById('hook') as HTMLInputElement).value as HookType;
const inputs = [...document.querySelectorAll('form input')] as HTMLInputElement[];
inputs?.forEach((input) => {
input.addEventListener('blur', validate);
input.addEventListener('input', clearErrors);
});
</script>