formique 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/README.md +179 -83
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -3,7 +3,17 @@
3
3
  <!-- <img src="https://github.com/thincmedia/anyGridJs/blob/main/images/anyGridJs_Example.png" alt="anyGridJs Example"> -->
4
4
 
5
5
 
6
- Formique: A lightweight, declarative JavaScript library for generating forms. Suited for vanilla js needs and Semantq JS framework. Formique simplifies the process of creating and managing forms with a variety of input types, built-in validation, and customizable attributes. Open-source &amp; MIT licensed.
6
+ Formique: A lightweight, declarative JavaScript syntax library for generating WCAG acceAccessibility compliant forms. Suited for vanilla js and Semantq JS framework. Formique simplifies the process of creating and managing forms with a variety of input types, built-in validation, and customizable attributes. Open-source &amp; MIT licensed.
7
+
8
+
9
+ ## Accessibility Compliance
10
+
11
+ Formique is designed with a laser focus on usability and accessibility, ensuring that the generated form HTML markup meets the highest standards of web accessibility, such as the Web Content Accessibility Guidelines (WCAG) 2.1.
12
+
13
+ With minimal declarative form input definitions, Formique takes care of the rest to ensure the final markup is comprehensive enough to meet [official](https://www.w3.org/WAI/tutorials/forms/) usability and accessibility standards.
14
+
15
+ For more information on the Web Content (Forms) Accessibility Guidelines (WCAG), you can visit the [W3C website](https://www.w3.org/WAI/tutorials/forms/).
16
+
7
17
 
8
18
  ## Key Features
9
19
 
@@ -17,10 +27,10 @@ Formique: A lightweight, declarative JavaScript library for generating forms. Su
17
27
 
18
28
  ## Why Choose Formique?
19
29
 
20
- - Vanilla JS: No dependencies; works seamlessly with vanilla JS or any JS framework.
30
+ - Vanilla JS: No dependencies; works seamlessly with vanilla JS and Semantq JS framework.(More frameworks to be added)
21
31
  - Lightweight: Minimal footprint optimized for performance.
22
32
  - Customizable: Adapt the library to fit your project's unique needs.
23
- - Declarative: Define forms with a straightforward schema for better readability and maintainability.
33
+ - Declarative: Write your forms in JavaScript and define forms with a concise schema for better readability and maintainability.
24
34
 
25
35
 
26
36
  ## Form Input Types Covered
@@ -53,12 +63,29 @@ Formique: A lightweight, declarative JavaScript library for generating forms. Su
53
63
  # How to Write Form Schema
54
64
 
55
65
  The form schema is an array of field definitions. Each field is defined by an array containing:
66
+ - Input definition (required)
67
+ - Input validation (optional)
68
+ - Input attributes (optional)
69
+ - Binding syntax (optional)
70
+ - Options (applicable to single select, multiple select, radio and check box inputs)
56
71
 
57
72
  ## Input Definition
58
73
  - **Type**: The input type (e.g., 'text', 'email', 'radio').
59
- - **Name**: The name attribute for the input.
74
+ - **Name**: The name attribute for the input.
60
75
  - **Label**: The label for the input.
61
76
 
77
+ You don't need to use the type, name and label keys to define these parameters.
78
+ **Example Input Definition:**
79
+
80
+ `{ 'text', 'firstname', 'First Name' }`
81
+
82
+ In the example above:
83
+ - The first item (text) defines the type of the input - this will yield: `<input type="text"`
84
+ - The second item (firstname) defines the name value of the input - this will yield: `<input name="firstname"`
85
+ - The third item (First Name) defines the Label value- this will yield: `<label for="firstname">First Name</label>`
86
+
87
+
88
+
62
89
  ## Input Validation
63
90
  - **Validation**: Object specifying validation rules. This can include:
64
91
  - **Required**: Boolean to specify if the field is mandatory.
@@ -68,95 +95,179 @@ The form schema is an array of field definitions. Each field is defined by an ar
68
95
  - **MaxLength**: Specifies the maximum number of characters allowed.
69
96
  - Example: `maxlength: 50`
70
97
  - **Pattern**: A regex pattern the input must match.
71
- - Example: `pattern: /^[A-Za-z0-9]+$/`
72
- - **Custom**: Function for custom validation logic.
73
- - Example: `custom: value => value.startsWith('A')`
98
+ - Example: `pattern: "/^[A-Za-z0-9]+$/"`
99
+
100
+ **Formique will filter out any invalid validation defined and throw warnings on the browser console.E.g. you define min and max validations for a text field Formique will filter these out.**
101
+
74
102
 
75
103
  ## Input Attributes
76
104
  - **Attributes**: Object specifying additional attributes like `id`, `class`, `style`, etc.
77
- - Example: `attributes: { id: 'username', class: 'form-control' }`
105
+ - Example: `{ id: 'username', class: 'form-input', style: 'font-size: 13px;' }`
78
106
 
79
107
  ## Binding
80
108
  - **Binding**: Optional binding syntax for dynamic data. It can use `bind:value` or `::inputName`.
81
- - Example: `binding: 'bind:value'` or `binding: '::username'`
109
+ - Example: `'bind:value'` or `'::inputName'` - inputName must be the value defined as the input name (second item) in the input definition object.
82
110
 
83
111
  ## Options
84
- - **Options**: For select, radio, and checkbox inputs. This is an array of options, each with a `value` and `label`.
85
- - Example: `options: [{ value: 'male', label: 'Male' }, { value: 'female', label: 'Female' }]`
112
+ - **Options**: For singleSelect,, multipleSelect, radio, and checkbox inputs. This is an array of options, each with a `value` and `label`.
113
+ - Example: `[{ value: 'male', label: 'Male' }, { value: 'female', label: 'Female' }]`
86
114
 
115
+ ### Selected Options
116
+ For fields like singleSelect and multipleSelect you can also define default or pre selected options this way:
87
117
 
118
+ `[{ value: 'red', label: 'Red' }, { value: 'blue', label: 'Blue', selected: true }]`
88
119
 
89
- ## Usage Example
120
+ In the example given: the blue option will be selected by default.
90
121
 
91
122
 
92
- There are two ways to use install Formique in your project
123
+ ## Installation
93
124
 
94
- ## Option A: Clone the GitHub repo:
125
+ There are two ways to install and use Formique in your project:
95
126
 
96
- 1. go to your terminal and run:
127
+ ## Option A: Use Formique as a Universal Module Definition (UMD) Module
97
128
 
98
- ```bash
99
- git clone https://github.com/Gugulethu-Nyoni/formique.git
129
+ 1. Include the CSS and JavaScript in the head section of your HTML file:
100
130
 
101
- ````
102
- 2. now you can use anygridjs this way in your html file
131
+ ```html
132
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/formique-css@1.0.1/formique.min.css">
133
+ ```
103
134
 
104
- ```html
135
+ 2. Insert the js script tag just before the closing tag ```html </body> ``` of your html file.
105
136
 
106
- <link rel="stylesheet" href="./formique/formique.css">
137
+ ```html
138
+ <script src="https://cdn.jsdelivr.net/npm/formique@1.0.1/formique.umd.js"></script>
139
+ ```
140
+ ## Usage Example
107
141
 
108
- ```
142
+ 1. Define the form container somewhere in the html body:
109
143
 
110
144
  ```html
111
-
112
- <script type="module">
113
-
114
- import { Formique } from './formique/formique.js';
115
-
116
- </script>
117
-
145
+ <div id="formique"></div>
118
146
  ```
119
147
 
120
148
 
121
- ## Option B: Via npm
122
-
123
- ### Installation
124
-
125
-
126
- 1. go to your terminal and run:
127
-
128
- ```bash
129
-
130
- npm install formique
131
-
132
- ````
133
-
134
- 2. now you can use formique this way in your html file
149
+ 2. Define your form parameters (formParams), form schema (formSchema) and then initialize Formique in script which should go below this script tag:
135
150
 
136
151
  ```html
137
-
138
- <link rel="stylesheet" href="./node_modules/formique/formique.css">
139
-
152
+ <script src="https://cdn.jsdelivr.net/npm/formique@1.0.1/formique.umd.js"></script>
140
153
  ```
141
154
 
142
- ```html
143
-
144
- <script type="module">
145
155
 
146
- import { Formique } from './node_modules/formique/formique.js';
147
-
148
- // rest of js code (app.js) can come here e.g. data object, column definition etc ( see below)
149
-
150
- </script>
156
+ ```html
157
+ <script src="https://cdn.jsdelivr.net/npm/formique@1.0.1/formique.umd.js"></script>
158
+
159
+ <script>
160
+ const formParams = {
161
+ method: 'post',
162
+ action: 'submit.js',
163
+ id: 'myForm',
164
+ class: 'form',
165
+ semantq: true,
166
+ style: 'width: 100%; font-size: 14px;'
167
+ };
168
+
169
+ const formSchema = [
170
+ ['text', 'name', 'Name', { required: true }, {}, ''],
171
+ ['email', 'email', 'Email', { required: true }, {}, ''],
172
+ [
173
+ 'singleSelect', 'diet', 'Dietary Requirements', {required: true}, {}, '',
174
+ [
175
+ {value: 'gluten-free', label: 'Gluten-free'},
176
+ {value: 'dairy-free', label: 'Dairy-free'},
177
+ {value: 'keto', label: 'Ketogenic'},
178
+ {value: 'low-carb', label: 'Low-carb'},
179
+ {value: 'pescatarian', label: 'Pescatarian'},
180
+ {value: 'halal', label: 'Halal'},
181
+ {value: 'kosher', label: 'Kosher'},
182
+ {value: 'vegetarian', label: 'Vegetarian'},
183
+ {value: 'lacto-ovo-vegetarian', label: 'Lacto-ovo-vegetarian'},
184
+ {value: 'raw-food', label: 'Raw food'},
185
+ {value: 'macrobiotic', label: 'Macrobiotic'},
186
+ {value: 'flexitarian', label: 'Flexitarian'}
187
+ ]
188
+ ],
189
+ ['submit', 'submitButton', 'Submit', {}, {}, '']
190
+ ];
191
+
192
+
193
+ (function(formParams, formSchema) {
194
+ const form = new Formique(formParams, formSchema);
195
+ const formHTML = form.renderFormHTML();
196
+ })(formParams, formSchema);
197
+
198
+ </script>
199
+ // </body>
200
+ ```
201
+
202
+ ## Option B: Use Formique as an ESM Module
203
+
204
+ 1. Install Formique via npm:
205
+
206
+ ```bash
207
+ npm install formique
208
+ ```
209
+
210
+ 2. Include the CSS and import Formique in the head section of your HTML file:
211
+
212
+ ```html
213
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/formique-css@1.0.1/formique.min.css">
214
+ ```
215
+ 3. Define form container somewhere in the html body:
151
216
 
217
+ ```html
218
+ <div id="formique"></div>
152
219
  ```
153
220
 
154
-
155
- # Example Usage
156
-
157
- ## Form Schema
158
-
159
- Here's an example of a form schema that defines various input fields with validation, attributes, options, and binding syntax:
221
+ 4. Define your form parameters (formParams), form schema (formSchema) and then initialize Formique in script which should go before the ```html </body> ``` tag.
222
+
223
+ ```html
224
+ <script type="module">
225
+ import Formique from 'formique';
226
+
227
+ const formParams = {
228
+ method: 'post',
229
+ action: 'submit.js',
230
+ id: 'myForm',
231
+ class: 'form',
232
+ semantq: true,
233
+ style: 'width: 100%; font-size: 14px;'
234
+ };
235
+
236
+ const formSchema = [
237
+ ['text', 'name', 'Name', { required: true }, {}, ''],
238
+ ['email', 'email', 'Email', { required: true }, {}, ''],
239
+ [
240
+ 'singleSelect', 'diet', 'Dietary Requirements', {required: true}, {}, '',
241
+ [
242
+ {value: 'gluten-free', label: 'Gluten-free'},
243
+ {value: 'dairy-free', label: 'Dairy-free'},
244
+ {value: 'keto', label: 'Ketogenic'},
245
+ {value: 'low-carb', label: 'Low-carb'},
246
+ {value: 'pescatarian', label: 'Pescatarian'},
247
+ {value: 'halal', label: 'Halal'},
248
+ {value: 'kosher', label: 'Kosher'},
249
+ {value: 'vegetarian', label: 'Vegetarian'},
250
+ {value: 'lacto-ovo-vegetarian', label: 'Lacto-ovo-vegetarian'},
251
+ {value: 'raw-food', label: 'Raw food'},
252
+ {value: 'macrobiotic', label: 'Macrobiotic'},
253
+ {value: 'flexitarian', label: 'Flexitarian'}
254
+ ]
255
+ ],
256
+ ['submit', 'submitButton', 'Submit', {}, {}, ''],
257
+ ];
258
+
259
+ const form = new Formique(formParams, formSchema);
260
+ const formHTML = form.renderFormHTML();
261
+
262
+ </script>
263
+ ```
264
+
265
+ Formique can be used as either a UMD module with a simple `<script>` tag or as an ESM module via npm.
266
+
267
+ # Form Schema Example
268
+
269
+
270
+ Here's an example of a form schema that defines various input fields with validation, attributes, binding syntax and options:
160
271
 
161
272
  ```javascript
162
273
  const formSchema = [
@@ -269,13 +380,9 @@ const formParams = {
269
380
  style: 'width: 100%; font-size: 14px;' // Inline CSS styling
270
381
  };
271
382
 
272
- const form = new Formique(formParams, formSchema);
273
- const formHTML = form.renderFormHTML();
274
- console.log(formHTML);
275
383
  ```
276
384
 
277
385
 
278
-
279
386
  # Full List of Possible Form Parameters
280
387
 
281
388
  ```javascript
@@ -299,7 +406,7 @@ const formParams = {
299
406
  - **action**: The URL where the form data will be submitted.
300
407
  - **id**: A unique identifier for the form.
301
408
  - **class**: CSS class names applied to the form for styling purposes.
302
- - **semantq**: Boolean value indicating whether to use semantic HTML elements (e.g., `<fieldset>`, `<legend>`).
409
+ - **semantq**: Boolean value to add syntax sugar in the Semantq JS Framework use case. If set event handler attributes will be rendered in the format: @click={incrementer}
303
410
  - **style**: Inline CSS styling applied directly to the form element.
304
411
  - **enctype**: Specifies how the form data should be encoded when submitted ('application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain').
305
412
  - **target**: Specifies where to display the response after submitting the form ('_self', '_blank', '_parent', '_top').
@@ -310,15 +417,6 @@ By customizing these parameters, you can control various aspects of the form's b
310
417
 
311
418
 
312
419
 
313
- ## HTML
314
-
315
- In your html, place this markup as placegolder for where the form will be rendered.
316
-
317
- ```html
318
-
319
- <div id="formique"></div>
320
-
321
- ```
322
420
 
323
421
  ## Example HTML Output
324
422
 
@@ -495,24 +593,22 @@ In your html, place this markup as placegolder for where the form will be render
495
593
 
496
594
  Formique provides a set of CSS classes to facilitate the styling of various form elements. The default class names for different form components are as follows:
497
595
 
498
- - **Wrapper for Input Elements:** `input-block`
596
+ - **Wrapper (div) for Input Elements:** `input-block`
499
597
  - **Input Fields:** `form-input`
500
598
  - **Radio Button Groups:** `radio-group`
501
599
  - **Checkbox Groups:** `checkbox-group`
502
600
  - **Select Dropdowns:** `form-select`
503
601
 
504
- These classes are predefined in the `formique.css` stylesheet. Developers can either use this stylesheet for consistent styling or create their own custom CSS based on these class names to suit their design preferences.
602
+ These classes are predefined in the `formique.css` stylesheet. Developers can either use this stylesheet for consistent styling or create their own custom CSS based on these class names to suit their design preferences. Also, Formique implements these class names by default. The input class can be overidden by defining your preferred class names in the input attributes object e.g.
505
603
 
506
- ### Customizing Styles
604
+ ```javascript
605
+ { class: 'form-control' }
606
+ ```
507
607
 
508
- 1. **Using Default Styles:** Apply the `formique.css` stylesheet to leverage the default styling provided by Formique.
509
- 2. **Custom CSS:** If you prefer custom styling, you can override the default styles by defining your own CSS rules for the above class names.
510
608
 
511
609
  ### Inline Styling
512
610
 
513
- In addition to external stylesheets, individual form elements can be styled directly via attributes specified in the form schema. This allows for precise control over the appearance of each element without needing additional CSS files.
514
-
515
- By utilizing these options, you can easily adapt the look and feel of your form to meet your project's design requirements.
611
+ In addition to external stylesheets, individual form elements can be styled directly via attributes specified in the form schema. This allows for fine grained control over the appearance of each element.
516
612
 
517
613
 
518
614
  ## Contribute
@@ -525,4 +621,4 @@ Formique is licensed under the MIT License.
525
621
 
526
622
  ## Keywords
527
623
 
528
- Javascript datatables.
624
+ Javascript forms, declarative form syntax, js form library.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formique",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Formique Declarative Form Syntax JavaScript Library",
5
5
  "main": "dist/formique.umd.js",
6
6
  "module": "dist/formique.esm.js",
@@ -11,4 +11,4 @@
11
11
  "keywords": [],
12
12
  "author": "",
13
13
  "license": "ISC"
14
- }
14
+ }