Skip to content

Commit 6fe0a67

Browse files
authored
Merge pull request #92 from horprogs/allow-using-elements-as-keys
#64 Allow using elements as keys
2 parents 9b3ea02 + 0fcf083 commit 6fe0a67

17 files changed

+1170
-602
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Test and Release
22
on:
33
workflow_dispatch:
44
push:
5+
branches:
6+
- master
57
jobs:
68
test:
79
name: Lint and Test

site/documentation/index.html

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@
138138
>showSuccessLabels</a
139139
>
140140
</li>
141+
<li class="nav-item">
142+
<a class="nav-link scrollto" href="#section-5-13"
143+
>setCurrentLocale</a
144+
>
145+
</li>
141146
<li class="nav-item section-title mt-3">
142147
<a class="nav-link scrollto" href="#section-6">Rules</a>
143148
</li>
@@ -231,7 +236,7 @@ <h2>yarn</h2>
231236
<header class="docs-header">
232237
<h1 class="docs-heading">
233238
Quick start
234-
<span class="docs-time">Last updated: 2022-03-16</span>
239+
<span class="docs-time">Last updated: 2022-12-10</span>
235240
</h1>
236241
</header>
237242
<section class="docs-intro">
@@ -292,6 +297,23 @@ <h1 class="docs-heading">
292297
rule: 'email',
293298
errorMessage: 'Email is invalid!',
294299
},
300+
]);</code></pre>
301+
<br />
302+
Also it is possible to use a DOM element as a field in the
303+
<code>.addField()</code> method.
304+
305+
<pre><code class="language-javascript">
306+
validation
307+
.addField(document.querySelector('#email'), [
308+
{
309+
rule: 'minLength',
310+
value: 3,
311+
},
312+
{
313+
rule: 'maxLength',
314+
value: 30,
315+
},
316+
])
295317
]);</code></pre>
296318
And that's it! Now our form is validated!
297319
</section>
@@ -734,15 +756,15 @@ <h1 class="docs-heading">
734756
<header class="docs-header">
735757
<h1 class="docs-heading">
736758
Methods
737-
<span class="docs-time">Last updated: 2022-05-18</span>
759+
<span class="docs-time">Last updated: 2022-12-09</span>
738760
</h1>
739761
</header>
740762
<section class="docs-section" id="section-5-1">
741763
<h2 class="section-heading">addField</h2>
742764
<p>Defines validation rules for the new field.</p>
743765

744766
<pre><code class="language-html">.addField(<br />
745-
&nbsp;&nbsp;field: string,<br />
767+
&nbsp;&nbsp;field: string | HTMLInputElement,<br />
746768
&nbsp;&nbsp;rules: {<br />
747769
&nbsp;&nbsp; &nbsp;rule?: Rules;<br />
748770
&nbsp;&nbsp; &nbsp;errorMessage?: string | (<br />
@@ -1021,7 +1043,7 @@ <h2 class="section-heading">revalidateField</h2>
10211043
Method to trigger a field validation manually. Returns a promise
10221044
with a boolean value - valid/invalid field.
10231045
</p>
1024-
<pre><code class="language-html">.revalidateField(field: string).then(isValid =&gt; {})</code></pre>
1046+
<pre><code class="language-html">.revalidateField(field: string | HTMLInputElement).then(isValid =&gt; {})</code></pre>
10251047
</section>
10261048
<section class="docs-section" id="section-5-6">
10271049
<h2 class="section-heading">revalidate</h2>
@@ -1053,7 +1075,7 @@ <h2 class="section-heading">removeField</h2>
10531075
Method to remove validation rules/events/errors from the
10541076
particular field
10551077
</p>
1056-
<pre><code class="language-html">.removeField(field: string)</code></pre>
1078+
<pre><code class="language-html">.removeField(field: string | HTMLInputElement)</code></pre>
10571079
</section>
10581080
<section class="docs-section" id="section-5-10">
10591081
<h2 class="section-heading">removeGroup</h2>
@@ -1077,6 +1099,13 @@ <h2 class="section-heading">showSuccessLabels</h2>
10771099
<p>For example:</p>
10781100
<pre><code class="language-html">.showSuccessLabels({ '#email': 'The email looks good!' })</code></pre>
10791101
</section>
1102+
<section class="docs-section" id="section-5-13">
1103+
<h2 class="section-heading">setCurrentLocale</h2>
1104+
<p>Method to change current locale</p>
1105+
<pre><code class="language-html">.setCurrentLocale(locale?: string)</code></pre>
1106+
<p>For example:</p>
1107+
<pre><code class="language-html">.setCurrentLocale('es')</code></pre>
1108+
</section>
10801109

10811110
<!--//section-->
10821111
</article>

src/demo.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const basic = (): void => {
2121
lockForm: true,
2222
});
2323

24+
const emailElem = document.querySelector(
25+
'#example1_email'
26+
) as HTMLInputElement;
27+
2428
validation
2529
.addField('#example1_name', [
2630
{
@@ -32,7 +36,7 @@ const basic = (): void => {
3236
value: 15,
3337
},
3438
])
35-
.addField('#example1_email', [
39+
.addField(emailElem, [
3640
{
3741
rule: 'required' as Rules,
3842
},
@@ -62,6 +66,17 @@ const basic = (): void => {
6266
ev?.preventDefault();
6367
window.showNotification();
6468
});
69+
70+
validation.addField('#example1_name', [
71+
{
72+
rule: 'minLength' as Rules,
73+
value: 10,
74+
},
75+
{
76+
rule: 'maxLength' as Rules,
77+
value: 15,
78+
},
79+
]);
6580
};
6681

6782
const advanced = (): void => {

0 commit comments

Comments
 (0)