kilvalidate 1.0.71 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ # KilValidate for Next.js (Client Only)
2
+
3
+ KilValidate is a DOM-based validator. It must run in the browser and is intended for client components. It does not use React state or form libraries internally; it reads and writes the DOM (error nodes, borders, etc.).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i kilvalidate
9
+ ```
10
+
11
+ ## Quick Start (App Router)
12
+
13
+ ```js
14
+ 'use client';
15
+ import React from 'react';
16
+ import { useKilvalidate } from 'kilvalidate/kilnextvalidation-react';
17
+
18
+ export default function Page() {
19
+ useKilvalidate();
20
+
21
+ return (
22
+ <form id="signup">
23
+ <input name="firstname" required />
24
+ <button type="submit">Submit</button>
25
+ </form>
26
+ );
27
+ }
28
+ ```
29
+
30
+ ## Quick Start (Pages Router)
31
+
32
+ ```js
33
+ import React, { useRef } from 'react';
34
+ import { useKilvalidate } from 'kilvalidate/kilnextvalidation-react';
35
+
36
+ export default function Page() {
37
+ const formRef = useRef(null);
38
+ useKilvalidate({ form: formRef });
39
+
40
+ return (
41
+ <form id="signup" ref={formRef}>
42
+ <input name="firstname" required />
43
+ <button type="submit">Submit</button>
44
+ </form>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ## Hook Options
50
+
51
+ - `useKilvalidate()` attaches to all forms on the page.
52
+ - `useKilvalidate({ form: formRef })` attaches only to a specific form.
53
+ - `useKilvalidate({ auto: false })` disables auto-init if you want manual control.
54
+
55
+ ## Manual Init (No Hook)
56
+
57
+ ```js
58
+ 'use client';
59
+ import kilvalidate from 'kilvalidate';
60
+
61
+ export default function Page() {
62
+ return (
63
+ <form id="signup" onSubmit={(e) => kilvalidate.validateForm('#signup', e)}>
64
+ <input name="firstname" required />
65
+ <button type="submit">Submit</button>
66
+ </form>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ## React Form Libraries
72
+
73
+ KilValidate can be used alongside form libraries, but it will not update React state. You can run it inside your submit handler to block submit:
74
+
75
+ ```js
76
+ import kilvalidate from 'kilvalidate';
77
+
78
+ function onSubmit(e) {
79
+ if (!kilvalidate.validateForm('#signup', e)) return;
80
+ // proceed with your submit
81
+ }
82
+ ```
83
+
84
+ If you need fully state-driven validation (errors as JS objects), the validator would need to be refactored to return structured error data instead of writing to the DOM. I can add that as a separate module if you want.
85
+
86
+ ## Notes
87
+
88
+ - Use only in client components.
89
+ - It injects CSS and writes error elements directly to the DOM.
90
+ - You can opt out per field with `data-ignore-kilvish`.
@@ -0,0 +1,42 @@
1
+ 'use client';
2
+
3
+ const React = require('react');
4
+ const { useEffect } = React;
5
+ const kilvalidateModule = require('./kilnextvalidation.js');
6
+
7
+ function getKilvalidate() {
8
+ return kilvalidateModule && kilvalidateModule.default ? kilvalidateModule.default : kilvalidateModule;
9
+ }
10
+
11
+ function resolveFormTarget(target) {
12
+ if (!target) return null;
13
+ if (target.current) return target.current;
14
+ return target;
15
+ }
16
+
17
+ function useKilvalidate(options = {}) {
18
+ const { form, auto = true } = options;
19
+
20
+ useEffect(() => {
21
+ if (!auto) return;
22
+ if (typeof window === 'undefined') return;
23
+ const api = getKilvalidate();
24
+ if (!api) return;
25
+
26
+ const formTarget = resolveFormTarget(form);
27
+ if (formTarget) {
28
+ api.addRealTimeValidation(formTarget);
29
+ api.attachInputEvents();
30
+ api.addAsteriskToRequiredFields();
31
+ api.addValidateFormToSubmitButtons();
32
+ api.initPasswordStrengthMeter();
33
+ } else {
34
+ api.init();
35
+ }
36
+ }, [form, auto]);
37
+ }
38
+
39
+ module.exports = {
40
+ useKilvalidate,
41
+ getKilvalidate
42
+ };