formique 1.0.1 → 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.
- package/README.md +624 -0
- package/package.json +6 -5
- package/formique.js +0 -2939
package/README.md
ADDED
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
# Formique
|
|
2
|
+
|
|
3
|
+
<!-- <img src="https://github.com/thincmedia/anyGridJs/blob/main/images/anyGridJs_Example.png" alt="anyGridJs Example"> -->
|
|
4
|
+
|
|
5
|
+
|
|
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 & 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
|
+
|
|
17
|
+
|
|
18
|
+
## Key Features
|
|
19
|
+
|
|
20
|
+
- Declarative Syntax: Define forms using a simple and intuitive schema.
|
|
21
|
+
- Wide Range of Inputs: Supports text, email, number, password, date, time, file uploads, and more.
|
|
22
|
+
- Validation and Attributes: Easily specify validation rules and attributes for each form field.
|
|
23
|
+
- Dynamic Form Generation: Generate forms dynamically based on your schema.
|
|
24
|
+
- Framework Agnostic: Currently works Semantq and vanilla JS.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Why Choose Formique?
|
|
29
|
+
|
|
30
|
+
- Vanilla JS: No dependencies; works seamlessly with vanilla JS and Semantq JS framework.(More frameworks to be added)
|
|
31
|
+
- Lightweight: Minimal footprint optimized for performance.
|
|
32
|
+
- Customizable: Adapt the library to fit your project's unique needs.
|
|
33
|
+
- Declarative: Write your forms in JavaScript and define forms with a concise schema for better readability and maintainability.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Form Input Types Covered
|
|
37
|
+
|
|
38
|
+
- Text: ```html <input type="text"> ```
|
|
39
|
+
- Email: ```html <input type="email"> ```
|
|
40
|
+
- Number: ```html <input type="number"> ```
|
|
41
|
+
- Password: ```html <input type="password"> ```
|
|
42
|
+
- Telephone: ```html <input type="tel"> ```
|
|
43
|
+
- Date: ```html <input type="date"> ```
|
|
44
|
+
- Time: ```html <input type="time"> ```
|
|
45
|
+
- Datetime-local: ```html <input type="datetime-local"> ```
|
|
46
|
+
- Month: ```html <input type="month"> ```
|
|
47
|
+
- Week: ```html <input type="week"> ```
|
|
48
|
+
- URL: ```html <input type="url"> ```
|
|
49
|
+
- Search: ```html <input type="search"> ```
|
|
50
|
+
- Color: ```html <input type="color"> ```
|
|
51
|
+
- File: ```html <input type="file"> ```
|
|
52
|
+
- Hidden: ```html <input type="hidden"> ```
|
|
53
|
+
- Image: ```html <input type="image"> ```
|
|
54
|
+
- Textarea: ```html <textarea> ```
|
|
55
|
+
- Radio: ```html <input type="radio"> ```
|
|
56
|
+
- Checkbox: ```html <input type="checkbox"> ```
|
|
57
|
+
- Select (Single & Multiple): ```html <select> ```
|
|
58
|
+
- Submit: ```html <input type="submit"> ```
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# How to Write Form Schema
|
|
64
|
+
|
|
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)
|
|
71
|
+
|
|
72
|
+
## Input Definition
|
|
73
|
+
- **Type**: The input type (e.g., 'text', 'email', 'radio').
|
|
74
|
+
- **Name**: The name attribute for the input.
|
|
75
|
+
- **Label**: The label for the input.
|
|
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
|
+
|
|
89
|
+
## Input Validation
|
|
90
|
+
- **Validation**: Object specifying validation rules. This can include:
|
|
91
|
+
- **Required**: Boolean to specify if the field is mandatory.
|
|
92
|
+
- Example: `required: true`
|
|
93
|
+
- **MinLength**: Specifies the minimum number of characters allowed.
|
|
94
|
+
- Example: `minlength: 5`
|
|
95
|
+
- **MaxLength**: Specifies the maximum number of characters allowed.
|
|
96
|
+
- Example: `maxlength: 50`
|
|
97
|
+
- **Pattern**: A regex pattern the input must match.
|
|
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
|
+
|
|
102
|
+
|
|
103
|
+
## Input Attributes
|
|
104
|
+
- **Attributes**: Object specifying additional attributes like `id`, `class`, `style`, etc.
|
|
105
|
+
- Example: `{ id: 'username', class: 'form-input', style: 'font-size: 13px;' }`
|
|
106
|
+
|
|
107
|
+
## Binding
|
|
108
|
+
- **Binding**: Optional binding syntax for dynamic data. It can use `bind:value` or `::inputName`.
|
|
109
|
+
- Example: `'bind:value'` or `'::inputName'` - inputName must be the value defined as the input name (second item) in the input definition object.
|
|
110
|
+
|
|
111
|
+
## Options
|
|
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' }]`
|
|
114
|
+
|
|
115
|
+
### Selected Options
|
|
116
|
+
For fields like singleSelect and multipleSelect you can also define default or pre selected options this way:
|
|
117
|
+
|
|
118
|
+
`[{ value: 'red', label: 'Red' }, { value: 'blue', label: 'Blue', selected: true }]`
|
|
119
|
+
|
|
120
|
+
In the example given: the blue option will be selected by default.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## Installation
|
|
124
|
+
|
|
125
|
+
There are two ways to install and use Formique in your project:
|
|
126
|
+
|
|
127
|
+
## Option A: Use Formique as a Universal Module Definition (UMD) Module
|
|
128
|
+
|
|
129
|
+
1. Include the CSS and JavaScript in the head section of your HTML file:
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/formique-css@1.0.1/formique.min.css">
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
2. Insert the js script tag just before the closing tag ```html </body> ``` of your html file.
|
|
136
|
+
|
|
137
|
+
```html
|
|
138
|
+
<script src="https://cdn.jsdelivr.net/npm/formique@1.0.1/formique.umd.js"></script>
|
|
139
|
+
```
|
|
140
|
+
## Usage Example
|
|
141
|
+
|
|
142
|
+
1. Define the form container somewhere in the html body:
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<div id="formique"></div>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
2. Define your form parameters (formParams), form schema (formSchema) and then initialize Formique in script which should go below this script tag:
|
|
150
|
+
|
|
151
|
+
```html
|
|
152
|
+
<script src="https://cdn.jsdelivr.net/npm/formique@1.0.1/formique.umd.js"></script>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
|
|
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:
|
|
216
|
+
|
|
217
|
+
```html
|
|
218
|
+
<div id="formique"></div>
|
|
219
|
+
```
|
|
220
|
+
|
|
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:
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
const formSchema = [
|
|
274
|
+
// Text Input Field
|
|
275
|
+
[
|
|
276
|
+
'text',
|
|
277
|
+
'firstName',
|
|
278
|
+
'First Name',
|
|
279
|
+
{ minlength: 2, maxlength: 5, required: true, disabled: true }, // Validation options
|
|
280
|
+
{ value: "John", id: 'firstNameInput', class: 'form-input', style: 'width: 100%;', oninput: "incrementer()" }, // Attributes
|
|
281
|
+
'::firstName' // Binding syntax
|
|
282
|
+
],
|
|
283
|
+
|
|
284
|
+
// URL Input Field
|
|
285
|
+
[
|
|
286
|
+
'url',
|
|
287
|
+
'websiteUrl',
|
|
288
|
+
'Website URL',
|
|
289
|
+
{ required: true }, // Validation options
|
|
290
|
+
{ id: 'websiteUrlInput', class: 'form-control', style: 'width: 100%;' }, // Attributes
|
|
291
|
+
'bind:value' // Binding syntax
|
|
292
|
+
],
|
|
293
|
+
|
|
294
|
+
// Radio Input Field
|
|
295
|
+
[
|
|
296
|
+
'radio',
|
|
297
|
+
'gender',
|
|
298
|
+
'Gender',
|
|
299
|
+
{ required: true }, // Validation options
|
|
300
|
+
{ id: 'genderRadio', class: 'form-radio-input', style: 'margin-left: 1rem;', onchange: 'actioner()' }, // Attributes
|
|
301
|
+
'::gender', // Binding syntax
|
|
302
|
+
[
|
|
303
|
+
{ value: 'male', label: 'Male' }, // Options
|
|
304
|
+
{ value: 'female', label: 'Female' },
|
|
305
|
+
{ value: 'other', label: 'Other' }
|
|
306
|
+
]
|
|
307
|
+
],
|
|
308
|
+
|
|
309
|
+
// Checkbox Input Field
|
|
310
|
+
[
|
|
311
|
+
'checkbox',
|
|
312
|
+
'preferences',
|
|
313
|
+
'Preferences',
|
|
314
|
+
{ required: true }, // Validation options
|
|
315
|
+
{ id: 'preferencesCheckbox', class: 'form-checkbox-input', style: 'margin-left: 1rem;', onchange: 'submit' }, // Attributes
|
|
316
|
+
'::preferences', // Binding syntax
|
|
317
|
+
[
|
|
318
|
+
{ value: 'news', label: 'Newsletter' }, // Options
|
|
319
|
+
{ value: 'updates', label: 'Product Updates' },
|
|
320
|
+
{ value: 'offers', label: 'Special Offers' }
|
|
321
|
+
]
|
|
322
|
+
],
|
|
323
|
+
|
|
324
|
+
// Single Select Input Field
|
|
325
|
+
[
|
|
326
|
+
'singleSelect',
|
|
327
|
+
'colors',
|
|
328
|
+
'Colors',
|
|
329
|
+
{ required: true }, // Validation options
|
|
330
|
+
{ id: 'colorsSelect', class: 'form-select-input', style: 'margin-left: 1rem;', onchange: 'trigger' }, // Attributes
|
|
331
|
+
'::colors', // Binding syntax
|
|
332
|
+
[
|
|
333
|
+
{ value: 'red', label: 'Red' }, // Options
|
|
334
|
+
{ value: 'green', label: 'Green' },
|
|
335
|
+
{ value: 'blue', label: 'Blue', selected: true }
|
|
336
|
+
]
|
|
337
|
+
],
|
|
338
|
+
|
|
339
|
+
// Multiple Select Input Field
|
|
340
|
+
[
|
|
341
|
+
'multipleSelect', // Type of field
|
|
342
|
+
'colors', // Name/identifier of the field
|
|
343
|
+
'Colors', // Label of the field
|
|
344
|
+
{ required: true, min: 2, max: 3 }, // Validation options
|
|
345
|
+
{ id: 'colorsSelect', class: 'form-select-input', style: 'margin-left: 1rem;', onchange: 'alerter' }, // Attributes
|
|
346
|
+
'::colors', // Binding syntax
|
|
347
|
+
[
|
|
348
|
+
{ value: 'red', label: 'Red' }, // Options
|
|
349
|
+
{ value: 'green', label: 'Green' },
|
|
350
|
+
{ value: 'blue', label: 'Blue' },
|
|
351
|
+
{ value: 'yellow', label: 'Yellow' }
|
|
352
|
+
]
|
|
353
|
+
],
|
|
354
|
+
|
|
355
|
+
// Submit Button
|
|
356
|
+
[
|
|
357
|
+
'submit',
|
|
358
|
+
'submitButton',
|
|
359
|
+
'Submit',
|
|
360
|
+
{ required: true }, // Validation options
|
|
361
|
+
{ id: 'submitBtn', class: 'form-submit-btn', style: 'margin-top: 1rem;' } // Attributes
|
|
362
|
+
]
|
|
363
|
+
];
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
# Invoking the Formique Class
|
|
368
|
+
|
|
369
|
+
To create a form using Formique, you need to define the form parameters and schema. Below is an example of how to invoke the class with basic parameters, followed by a full list of possible parameters.
|
|
370
|
+
|
|
371
|
+
## Basic Form Parameters
|
|
372
|
+
|
|
373
|
+
```javascript
|
|
374
|
+
const formParams = {
|
|
375
|
+
method: 'post', // HTTP method (e.g., 'get', 'post')
|
|
376
|
+
action: 'submit.js', // Form submission URL
|
|
377
|
+
id: 'myForm', // Unique identifier for the form
|
|
378
|
+
class: 'form', // CSS class for styling
|
|
379
|
+
semantq: true, // Whether to use semantic HTML elements
|
|
380
|
+
style: 'width: 100%; font-size: 14px;' // Inline CSS styling
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
# Full List of Possible Form Parameters
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
const formParams = {
|
|
390
|
+
method: 'post', // HTTP method (e.g., 'get', 'post')
|
|
391
|
+
action: 'submit.js', // Form submission URL
|
|
392
|
+
id: 'myForm', // Unique identifier for the form
|
|
393
|
+
class: 'form', // CSS class for styling
|
|
394
|
+
semantq: true, // if true it enables Semantq syntax sugar: i.e. attribute: onchange: 'handlerFunction' will be transformed to: @change={handlerFunction} if false or not defined completely the output would be regular html e.g.: onchange="handlerFunction()"
|
|
395
|
+
style: 'width: 100%; font-size: 14px;', // Inline CSS styling
|
|
396
|
+
enctype: 'multipart/form-data', // Encoding type for file uploads
|
|
397
|
+
target: '_blank', // Where to open the form result (e.g., '_self', '_blank')
|
|
398
|
+
novalidate: true, // Disable form validation
|
|
399
|
+
accept_charset: 'UTF-8' // this will be transformed to: accept-charset: 'UTF-8' Character set for form data
|
|
400
|
+
};
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## Explanation of Parameters
|
|
404
|
+
|
|
405
|
+
- **method**: Specifies the HTTP method to use when submitting the form ('get', 'post').
|
|
406
|
+
- **action**: The URL where the form data will be submitted.
|
|
407
|
+
- **id**: A unique identifier for the form.
|
|
408
|
+
- **class**: CSS class names applied to the form for styling purposes.
|
|
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}
|
|
410
|
+
- **style**: Inline CSS styling applied directly to the form element.
|
|
411
|
+
- **enctype**: Specifies how the form data should be encoded when submitted ('application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain').
|
|
412
|
+
- **target**: Specifies where to display the response after submitting the form ('_self', '_blank', '_parent', '_top').
|
|
413
|
+
- **novalidate**: Disables form validation when set to true.
|
|
414
|
+
- **accept_charset**: Specifies the character encoding used for form data submission.
|
|
415
|
+
|
|
416
|
+
By customizing these parameters, you can control various aspects of the form's behavior and appearance.
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
## Example HTML Output
|
|
422
|
+
|
|
423
|
+
```html
|
|
424
|
+
<div id="formique">
|
|
425
|
+
<form
|
|
426
|
+
method="post"
|
|
427
|
+
action="submit.js"
|
|
428
|
+
id="myForm"
|
|
429
|
+
class="form"
|
|
430
|
+
semantq
|
|
431
|
+
style="width: 100%; font-size: 14px;"
|
|
432
|
+
>
|
|
433
|
+
<div class="input-block">
|
|
434
|
+
<label for="firstNameInput">First Name</label>
|
|
435
|
+
<input
|
|
436
|
+
type="text"
|
|
437
|
+
name="firstName"
|
|
438
|
+
bind:value="firstName"
|
|
439
|
+
id="firstNameInput"
|
|
440
|
+
value="John"
|
|
441
|
+
class="form-input"
|
|
442
|
+
style="width: 100%;"
|
|
443
|
+
@input={incrementer}
|
|
444
|
+
minlength="2"
|
|
445
|
+
maxlength="5"
|
|
446
|
+
required
|
|
447
|
+
disabled
|
|
448
|
+
/>
|
|
449
|
+
</div>
|
|
450
|
+
<div class="input-block">
|
|
451
|
+
<label for="websiteUrlInput">Website URL</label>
|
|
452
|
+
<input
|
|
453
|
+
type="url"
|
|
454
|
+
name="websiteUrl"
|
|
455
|
+
bind:value="websiteUrl"
|
|
456
|
+
id="websiteUrlInput"
|
|
457
|
+
class="form-control"
|
|
458
|
+
style="width: 100%;"
|
|
459
|
+
required
|
|
460
|
+
/>
|
|
461
|
+
</div>
|
|
462
|
+
<fieldset class="radio-group">
|
|
463
|
+
<legend>Gender</legend>
|
|
464
|
+
<div>
|
|
465
|
+
<input
|
|
466
|
+
type="radio"
|
|
467
|
+
name="gender"
|
|
468
|
+
value="male"
|
|
469
|
+
bind:value="gender"
|
|
470
|
+
class="form-radio-input"
|
|
471
|
+
style="margin-left: 1rem;"
|
|
472
|
+
@change={actioner}
|
|
473
|
+
id="genderRadio-male"
|
|
474
|
+
/>
|
|
475
|
+
<label for="genderRadio-male">Male</label>
|
|
476
|
+
</div>
|
|
477
|
+
<div>
|
|
478
|
+
<input
|
|
479
|
+
type="radio"
|
|
480
|
+
name="gender"
|
|
481
|
+
value="female"
|
|
482
|
+
bind:value="gender"
|
|
483
|
+
class="form-radio-input"
|
|
484
|
+
style="margin-left: 1rem;"
|
|
485
|
+
@change={actioner}
|
|
486
|
+
id="genderRadio-female"
|
|
487
|
+
/>
|
|
488
|
+
<label for="genderRadio-female">Female</label>
|
|
489
|
+
</div>
|
|
490
|
+
<div>
|
|
491
|
+
<input
|
|
492
|
+
type="radio"
|
|
493
|
+
name="gender"
|
|
494
|
+
value="other"
|
|
495
|
+
bind:value="gender"
|
|
496
|
+
class="form-radio-input"
|
|
497
|
+
style="margin-left: 1rem;"
|
|
498
|
+
@change={actioner}
|
|
499
|
+
id="genderRadio-other"
|
|
500
|
+
/>
|
|
501
|
+
<label for="genderRadio-other">Other</label>
|
|
502
|
+
</div>
|
|
503
|
+
</fieldset>
|
|
504
|
+
<fieldset class="checkbox-group">
|
|
505
|
+
<legend>Preferences</legend>
|
|
506
|
+
<div>
|
|
507
|
+
<input
|
|
508
|
+
type="checkbox"
|
|
509
|
+
name="preferences"
|
|
510
|
+
value="news"
|
|
511
|
+
bind:checked="preferences"
|
|
512
|
+
class="form-checkbox-input"
|
|
513
|
+
style="margin-left: 1rem;"
|
|
514
|
+
@change={submit}
|
|
515
|
+
id="preferencesCheckbox-news"
|
|
516
|
+
/>
|
|
517
|
+
<label for="preferencesCheckbox-news">Newsletter</label>
|
|
518
|
+
</div>
|
|
519
|
+
<div>
|
|
520
|
+
<input
|
|
521
|
+
type="checkbox"
|
|
522
|
+
name="preferences"
|
|
523
|
+
value="updates"
|
|
524
|
+
bind:checked="preferences"
|
|
525
|
+
class="form-checkbox-input"
|
|
526
|
+
style="margin-left: 1rem;"
|
|
527
|
+
@change={submit}
|
|
528
|
+
id="preferencesCheckbox-updates"
|
|
529
|
+
/>
|
|
530
|
+
<label for="preferencesCheckbox-updates">Product Updates</label>
|
|
531
|
+
</div>
|
|
532
|
+
<div>
|
|
533
|
+
<input
|
|
534
|
+
type="checkbox"
|
|
535
|
+
name="preferences"
|
|
536
|
+
value="offers"
|
|
537
|
+
bind:checked="preferences"
|
|
538
|
+
class="form-checkbox-input"
|
|
539
|
+
style="margin-left: 1rem;"
|
|
540
|
+
@change={submit}
|
|
541
|
+
id="preferencesCheckbox-offers"
|
|
542
|
+
/>
|
|
543
|
+
<label for="preferencesCheckbox-offers">Special Offers</label>
|
|
544
|
+
</div>
|
|
545
|
+
</fieldset>
|
|
546
|
+
<fieldset class="form-select">
|
|
547
|
+
<label for="colorsSelect">Colors</label>
|
|
548
|
+
<select
|
|
549
|
+
name="colors"
|
|
550
|
+
bind:value="colors"
|
|
551
|
+
id="colorsSelect"
|
|
552
|
+
class="form-select-input"
|
|
553
|
+
style="margin-left: 1rem;"
|
|
554
|
+
@change={trigger}
|
|
555
|
+
required
|
|
556
|
+
>
|
|
557
|
+
<option value="">Choose an option</option>
|
|
558
|
+
<option value="red">Red</option>
|
|
559
|
+
<option value="green">Green</option>
|
|
560
|
+
<option value="blue" selected>Blue</option>
|
|
561
|
+
</select>
|
|
562
|
+
</fieldset>
|
|
563
|
+
<fieldset class="form-select">
|
|
564
|
+
<label for="colorsSelect">Colors</label>
|
|
565
|
+
<select
|
|
566
|
+
name="colors"
|
|
567
|
+
bind:value="colors"
|
|
568
|
+
id="colorsSelect"
|
|
569
|
+
class="form-select-input"
|
|
570
|
+
style="margin-left: 1rem;"
|
|
571
|
+
@change={alerter}
|
|
572
|
+
required
|
|
573
|
+
multiple
|
|
574
|
+
>
|
|
575
|
+
<option value="red">Red</option>
|
|
576
|
+
<option value="green">Green</option>
|
|
577
|
+
<option value="blue">Blue</option>
|
|
578
|
+
<option value="yellow">Yellow</option>
|
|
579
|
+
</select>
|
|
580
|
+
</fieldset>
|
|
581
|
+
<input
|
|
582
|
+
type="submit"
|
|
583
|
+
id="submitBtn"
|
|
584
|
+
value="Submit"
|
|
585
|
+
class="form-submit-btn"
|
|
586
|
+
style="margin-top: 1rem;"
|
|
587
|
+
/>
|
|
588
|
+
</form>
|
|
589
|
+
</div>
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
## Styling the Form
|
|
593
|
+
|
|
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:
|
|
595
|
+
|
|
596
|
+
- **Wrapper (div) for Input Elements:** `input-block`
|
|
597
|
+
- **Input Fields:** `form-input`
|
|
598
|
+
- **Radio Button Groups:** `radio-group`
|
|
599
|
+
- **Checkbox Groups:** `checkbox-group`
|
|
600
|
+
- **Select Dropdowns:** `form-select`
|
|
601
|
+
|
|
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.
|
|
603
|
+
|
|
604
|
+
```javascript
|
|
605
|
+
{ class: 'form-control' }
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
### Inline Styling
|
|
610
|
+
|
|
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.
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
## Contribute
|
|
615
|
+
|
|
616
|
+
Formique is an open-source project. Contributions, issues, and feature requests are welcome!
|
|
617
|
+
|
|
618
|
+
## License
|
|
619
|
+
|
|
620
|
+
Formique is licensed under the MIT License.
|
|
621
|
+
|
|
622
|
+
## Keywords
|
|
623
|
+
|
|
624
|
+
Javascript forms, declarative form syntax, js form library.
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formique",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Formique JavaScript
|
|
5
|
-
"main": "formique.js",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Formique Declarative Form Syntax JavaScript Library",
|
|
5
|
+
"main": "dist/formique.umd.js",
|
|
6
|
+
"module": "dist/formique.esm.js",
|
|
6
7
|
"files": [
|
|
7
|
-
"
|
|
8
|
+
"dist/*",
|
|
9
|
+
"README.md"
|
|
8
10
|
],
|
|
9
|
-
"scripts": {},
|
|
10
11
|
"keywords": [],
|
|
11
12
|
"author": "",
|
|
12
13
|
"license": "ISC"
|