@ng-formworks/cssframework 17.2.7 → 18.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.
package/README.md CHANGED
@@ -1,28 +1,834 @@
1
- # @ng-formworks/cssframework
2
1
 
3
- This module is a dependency of the [ng-formworks project][npm_core_ver] and not intended to be consumed independently see [@ng-formworks/core][npm_core_ver] for more details.
4
- Below is information regarding the development tasks and not related to the module's installation, it should automatically be installed when a framework module is installed.
5
2
 
6
- ## Code scaffolding
3
+ # ng-formworks
7
4
 
8
- Run `ng generate component component-name --project @ng-formworks/cssframework` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project @ng-formworks/cssframework`.
9
- > Note: Don't forget to add `--project @ng-formworks/cssframework` or else it will be added to the default project in your `angular.json` file.
5
+ This project is a continuation of [hamzahamidi/ajsf](https://github.com/hamzahamidi/ajsf) and [dschnelldavis/Angular2-json-schema-form](https://github.com/dschnelldavis/angular2-json-schema-form) and is not affiliated with any organization.
10
6
 
11
- ## Build
7
+ ng-formworks targets angular 15+ and also adds extra frameworks and theming support
12
8
 
13
- Run `ng build @ng-formworks/cssframework` to build the project. The build artifacts will be stored in the `dist/` directory.
9
+ [hamzahamidi/ajsf](https://github.com/hamzahamidi/ajsf) can be used for angular 14 and below
14
10
 
15
- ## Publishing
11
+ <p align="center">
16
12
 
17
- After building your library with `ng build @ng-formworks/cssframework`, go to the dist folder `cd dist/@ng-formworks/cssframework` and run `npm publish`.
18
13
 
19
- ## Running unit tests
14
+ <a href="https://angular.io/"><img src="https://img.shields.io/badge/angular-15,_16,_17,_18-red.svg?logo=Angular&logoColor=red&labelColor=white&style=plastic" alt="Angular Versions"></a>
15
+ <a href="https://github.com/zahmo/ng-formworks/actions?query=workflow%3ACI+branch%3Amain"><img src="https://github.com/zahmo/ng-formworks/workflows/CI/badge.svg" alt="CI Status"></a> <a href="https://www.npmjs.com/package/@ng-formworks/core"><img src="https://img.shields.io/npm/dm/@ng-formworks/core.svg?style=plastic" alt="npm number of downloads"></a><a href="https://github.com/zahmo/ng-formworks/blob/master/LICENSE"><img src="https://img.shields.io/github/license/zahmo/ng-formworks.svg?style=social" alt="LICENSE IMT"></a><a href="https://app.netlify.com/sites/ng-formworks/deploys"><img src="https://api.netlify.com/api/v1/badges/6c5b5a1d-db7c-4d0e-8ac1-a4840d8812f0/deploy-status" alt="Netlify Status"></a>
20
16
 
21
- Run `ng test @ng-formworks/cssframework` to execute the unit tests via [Karma](https://karma-runner.github.io).
22
17
 
23
- ## Further help
18
+ </p>
24
19
 
25
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
26
20
 
21
+ A [JSON Schema](http://json-schema.org) Form builder for Angular, similar to, and mostly API compatible with:
27
22
 
28
- [npm_core_ver]:https://www.npmjs.com/package/@ng-formworks/core
23
+ * [JSON Schema Form](https://github.com/json-schema-form)'s [Angular Schema Form](http://schemaform.io) for [AngularJS](https://angularjs.org) ([examples](http://schemaform.io/examples/bootstrap-example.html))
24
+
25
+
26
+ * [Mozilla](https://blog.mozilla.org/services/)'s [React JSON Schema Form](https://github.com/mozilla-services/react-jsonschema-form) for [React](https://facebook.github.io/react/) ([examples](https://mozilla-services.github.io/react-jsonschema-form/)), and
27
+
28
+
29
+ * [Joshfire](http://www.joshfire.com)'s [JSON Form](http://github.com/joshfire/jsonform/wiki) for [jQuery](https://jquery.com) ([examples](http://ulion.github.io/jsonform/playground/))
30
+
31
+
32
+ ## Versions
33
+
34
+
35
+ | angular | ng-formworks |
36
+ |--|--|
37
+ | 15.x.x |15.x.x|
38
+ | 16.x.x |16.x.x|
39
+ | 17.x.x |17.x.x|
40
+ | 18.x.x |18.x.x|
41
+
42
+
43
+ ## Packages
44
+
45
+ * [`@ng-formworks/core`][gh_core_project] [![npm version][npm_core_badge]][npm_core_ver][![npm RC version][npm_core_badge_alpha]][npm_core_ver_alpha]
46
+
47
+ * [`@ng-formworks/cssframework`][gh_cssframework_project] [![npm version][npm_cssframework_badge]][npm_cssframework_ver][![npm RC version][npm_cssframework_badge_alpha]][npm_cssframework_ver_alpha]
48
+
49
+ * [`@ng-formworks/bootstrap3`][gh_bootstrap3_project] [![npm version][npm_bootstrap3_badge]][npm_bootstrap3_ver][![npm RC version][npm_bootstrap3_badge_alpha]][npm_bootstrap3_ver_alpha]
50
+
51
+ * [`@ng-formworks/bootstrap4`][gh_bootstrap4_project] [![npm version][npm_bootstrap4_badge]][npm_bootstrap4_ver][![npm RC version][npm_bootstrap4_badge_alpha]][npm_bootstrap4_ver_alpha]
52
+
53
+
54
+ * [`@ng-formworks/bootstrap5`][gh_bootstrap5_project] [![npm version][npm_bootstrap5_badge]][npm_bootstrap5_ver][![npm RC version][npm_bootstrap5_badge_alpha]][npm_bootstrap5_ver_alpha]
55
+
56
+
57
+ * [`@ng-formworks/daisyui`][gh_daisyui_project] [![npm version][npm_daisyui_badge]][npm_daisyui_ver][![npm RC version][npm_daisyui_badge_alpha]][npm_daisyui_ver_alpha]
58
+
59
+
60
+ * [`@ng-formworks/material`][gh_material_project] [![npm version][npm_material_badge]][npm_material_ver][![npm RC version][npm_material_badge_alpha]][npm_material_ver_alpha]
61
+
62
+ ## Check out the live demo and play with the examples
63
+
64
+ [Check out some examples here.](https://zahmo.github.io/ng-formworks/)
65
+
66
+ This example playground features over 70 different JSON Schemas for you to try (including all examples used by each of the three libraries listed above), and the ability to quickly view any example formatted with Material Design, Bootstrap 3, Bootstrap 4, Bootstrap 5, DaisyUI or without any formatting.
67
+
68
+ ## Installation
69
+
70
+ ### To install from NPM/YARN and use in your own project
71
+
72
+ First decide on which frameworks you plan to use (more than one can be installed) and have a look at their specific READMES regarding their installation:
73
+
74
+ [@ng-formworks/material][npm_material_ver] — Material Design
75
+
76
+
77
+ [@ng-formworks/bootstrap3][npm_bootstrap3_ver] — Bootstrap 3
78
+
79
+
80
+ [@ng-formworks/bootstrap4][npm_bootstrap4_ver] — Bootstrap 4
81
+
82
+
83
+ [@ng-formworks/bootstrap5][npm_bootstrap5_ver] — Bootstrap 5
84
+
85
+
86
+ [@ng-formworks/daisyui][npm_daisyui_ver] — DaisyUi
87
+
88
+
89
+ [@ng-formworks/core][npm_core_ver] — plain HTML (for testing)
90
+
91
+ For example if you'd like to try the material design based framework, [install @ng-formworks/material package from NPM][npm_material_ver] which uses `material-angular` UI. You can use either [NPM](https://www.npmjs.com) or [Yarn](https://yarnpkg.com). To install with NPM, run the following from your terminal:
92
+
93
+
94
+ ```shell
95
+ npm install @ng-formworks/core@latest @ng-formworks/cssframework@latest @ng-formworks/material@latest
96
+ ```
97
+
98
+ With YARN, run the following:
99
+ ```shell
100
+ yarn add @ng-formworks/core@latest @ng-formworks/cssframework@latest @ng-formworks/material@latest
101
+ ```
102
+
103
+ include the themes scss in your applications sass file(typically "styles.scss" under "src" folder -see angular docs for more details)
104
+ ```scss
105
+ @import "node_modules/@ng-formworks/material/assets/material-design-themes.scss";
106
+ ```
107
+
108
+ Then import `MaterialDesignFrameworkModule` in your main application module like this:
109
+
110
+
111
+ ```javascript
112
+
113
+ import { BrowserModule } from '@angular/platform-browser';
114
+ import { NgModule } from '@angular/core';
115
+ import { MaterialDesignFrameworkModule } from '@ng-formworks/material';
116
+ import { AppComponent } from './app.component';
117
+
118
+ @NgModule({
119
+ declarations: [ AppComponent ],
120
+ imports: [
121
+ MaterialDesignFrameworkModule
122
+ ],
123
+ providers: [],
124
+ bootstrap: [ AppComponent ]
125
+ })
126
+
127
+ export class AppModule { }
128
+ ```
129
+
130
+ six framework modules are currently available, their import is similar to above and may vary slightly, have a look at their specific docs :
131
+
132
+ * MaterialDesignFrameworkModule from [@ng-formworks/material][npm_material_ver] — Material Design
133
+
134
+
135
+ * Bootstrap3FrameworkModule from [@ng-formworks/bootstrap3][npm_bootstrap3_ver] — Bootstrap 3
136
+
137
+
138
+ * Bootstrap4FrameworkModule from [@ng-formworks/bootstrap4][npm_bootstrap4_ver] — Bootstrap 4
139
+
140
+
141
+ * Bootstrap5FrameworkModule from [@ng-formworks/bootstrap5][npm_bootstrap5_ver] — Bootstrap 5
142
+
143
+
144
+ * DaisyUIFrameworkModule from [@ng-formworks/daisyui][npm_daisyui_ver] — DaisyUi
145
+
146
+
147
+ * JsonSchemaFormModule from [@ng-formworks/core][npm_core_ver] — plain HTML (for testing)
148
+
149
+ It is also possible to load multiple frameworks and switch between them at runtime, like the example playground on GitHub. But most typical sites will just load one framework.
150
+
151
+ ### To install from GitHub
152
+
153
+ To install [the library and the example playground from GitHub](https://github.com/zahmo/ng-formworks), clone `https://github.com/zahmo/ng-formworks.git` with your favorite git program. Or, assuming you have [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Node/YARN](https://nodejs.org/en/download/) installed, enter the following in your terminal:
154
+
155
+
156
+ ```shell
157
+ git clone https://github.com/zahmo/ng-formworks.git ng-formworks
158
+ cd ng-formworks
159
+ yarn install
160
+ yarn start
161
+ ```
162
+
163
+ This should start a server with the example playground, which you can view in your browser at `http://localhost:4200`
164
+
165
+ The source code is composed as the following:
166
+
167
+ * `projects/ng-formworks-core` - Angular JSON Schema Form main library
168
+
169
+
170
+ * `projects/ng-formworks-cssframework` - Framework module used to build other frameworks
171
+
172
+
173
+ * `projects/ng-formworks-bootstrap3` - Framework for Bootstrap 3
174
+
175
+
176
+ * `projects/ng-formworks-bootstrap4` - Framework for Bootstrap 4
177
+
178
+
179
+ * `projects/ng-formworks-bootstrap5` - Framework for Bootstrap 5
180
+
181
+
182
+ * `projects/ng-formworks-daisyui` - Framework for DaisyUI
183
+
184
+
185
+ * `projects/ng-formworks-material` - Framework for Angular Material
186
+
187
+
188
+ * `projects/ng-formworks-core/src/lib/framework-library` - framework library
189
+
190
+
191
+ * `projects/ng-formworks-core/src/lib/widget-library` - widget library
192
+
193
+
194
+ * `projects/ng-formworks-core/src/lib/shared` - various utilities and helper functions
195
+
196
+
197
+ * `demo` - the demonstration playground example application
198
+
199
+
200
+ * `demo/assets/example-schemas` - JSON Schema examples used in the playground
201
+
202
+ If you want detailed documentation describing the individual functions used in this library, check the README in each component. (Angular JSON Schema Form is still a work in progress, so right now this documentation varies from highly detailed to completely missing.)
203
+
204
+ ## Using Angular JSON Schema Form
205
+
206
+ ### Basic use
207
+
208
+ For basic use, after loading JsonSchemaFormModule as described above, to display a form in your Angular component, simply add the following to your component's template:
209
+
210
+
211
+ ```html
212
+ <json-schema-form
213
+ loadExternalAssets="true"
214
+ [schema]="yourJsonSchema"
215
+ framework="no-framework"
216
+ (onSubmit)="yourOnSubmitFn($event)">
217
+ </json-schema-form>
218
+ ```
219
+
220
+ Where `schema` is a valid JSON schema object, and `onSubmit` calls a function to process the submitted JSON form data. If you don't already have your own schemas, you can find a bunch of samples to test with in the `demo/assets/example-schemas` folder, as described above.
221
+
222
+ `framework` is for the template you want to use, the default value is `no-framwork`. The possible values are:
223
+
224
+ * `material-design` for Material Design (if installed).
225
+
226
+
227
+ * `bootstrap-3` for Bootstrap 3 (if installed).
228
+
229
+
230
+ * `bootstrap-4` for Bootstrap 4 (if installed).
231
+
232
+
233
+ * `bootstrap-5` for Bootstrap 5 (if installed).
234
+
235
+
236
+ * `daisyui` for DaisyUi.
237
+
238
+
239
+ * `no-framework` for (plain HTML).
240
+
241
+ Setting `loadExternalAssets="true"` will automatically load any additional assets needed by the display framework. It is useful when you are trying out this library, but production sites should instead load all required assets separately. For full details see 'Changing or adding frameworks', below.
242
+
243
+ ### Data-only mode
244
+
245
+ Angular JSON Schema Form can also create a form entirely from a JSON object—with no schema—like so:
246
+
247
+
248
+ ```html
249
+ <json-schema-form
250
+ loadExternalAssets="true"
251
+ [(ngModel)]="exampleJsonObject">
252
+ </json-schema-form>
253
+ ```
254
+
255
+ ```javascript
256
+ exampleJsonObject = {
257
+ "first_name": "Jane", "last_name": "Doe", "age": 25, "is_company": false,
258
+ "address": {
259
+ "street_1": "123 Main St.", "street_2": null,
260
+ "city": "Las Vegas", "state": "NV", "zip_code": "89123"
261
+ },
262
+
263
+ "phone_numbers": [
264
+ { "number": "702-123-4567", "type": "cell" },
265
+ { "number": "702-987-6543", "type": "work" }
266
+ ],
267
+ "notes": ""
268
+
269
+ };
270
+ ```
271
+
272
+ In this mode, Angular JSON Schema Form automatically generates a schema from your data. The generated schema is relatively simple, compared to what you could create on your own. However, as the above example shows, it does detect and enforce string, number, and boolean values (nulls are also assumed to be strings), and automatically allows array elements to be added, removed, and reordered.
273
+
274
+ After displaying a form in this mode, you can also use the `formSchema` and `formLayout` outputs (described in 'Debugging inputs and outputs', below), to return the generated schema and layout, which will give you a head start on writing your own schemas and layouts by showing you examples created from your own data.
275
+
276
+ Also, notice that the 'ngModel' input supports Angular's 2-way data binding, just like other form controls, which is why it is not always necessary to use an onSubmit function.
277
+
278
+ ### Advanced use
279
+
280
+ #### Additional inputs an outputs
281
+
282
+ For more control over your form, you may provide these additional inputs:
283
+
284
+ * `layout` array with a custom form layout (see Angular Schema Form's [form definitions](https://github.com/json-schema-form/angular-schema-form/blob/master/docs/index.md#form-definitions) for information about how to construct a form layout)
285
+
286
+
287
+ * `data` object to populate the form with default or previously submitted values
288
+
289
+
290
+ * `options` object to set any global options for the form
291
+
292
+
293
+ * `widgets` object to add custom widgets
294
+
295
+
296
+ * `language` string to set the error message language (currently supports 'de', 'en', 'es', 'fr', 'it', 'pt', 'zh')
297
+
298
+
299
+ * `framework` string or object to set which framework to use
300
+
301
+ For `framework`, you can pass in your own custom framework object, or, if you've loaded multiple frameworks, you can specify the name of the framework you want to use. To switch between the included frameworks, use 'material-design', 'bootstrap-3', 'bootstrap-4', and 'no-framework'.
302
+
303
+ If you want more detailed output, you may provide additional functions for `onChanges` to read the values in real time as the form is being filled out, and you may implement your own custom validation indicators from the boolean `isValid` or the detailed `validationErrors` outputs.
304
+
305
+ Here is an example:
306
+
307
+
308
+ ```html
309
+ <json-schema-form
310
+ [schema]="yourJsonSchema"
311
+ [layout]="yourJsonFormLayout"
312
+ [(data)]="yourData"
313
+ [options]="yourFormOptions"
314
+ [widgets]="yourCustomWidgets"
315
+ language="fr"
316
+ framework="material-design"
317
+ loadExternalAssets="true"
318
+ (onChanges)="yourOnChangesFn($event)"
319
+ (onSubmit)="yourOnSubmitFn($event)"
320
+ (isValid)="yourIsValidFn($event)"
321
+ (validationErrors)="yourValidationErrorsFn($event)">
322
+ </json-schema-form>
323
+ ```
324
+
325
+ Note: If you prefer brackets around all your attributes, the following is functionally equivalent:
326
+
327
+
328
+ ```html
329
+ <json-schema-form
330
+ [schema]="yourJsonSchema"
331
+ [layout]="yourJsonFormLayout"
332
+ [(data)]="yourData"
333
+ [options]="yourFormOptions"
334
+ [widgets]="yourCustomWidgets"
335
+ [language]="'fr'"
336
+ [framework]="'material-design'"
337
+ [loadExternalAssets]="true"
338
+ (onChanges)="yourOnChangesFn($event)"
339
+ (onSubmit)="yourOnSubmitFn($event)"
340
+ (isValid)="yourIsValidFn($event)"
341
+ (validationErrors)="yourValidationErrorsFn($event)">
342
+ </json-schema-form>
343
+ ```
344
+
345
+ If you use this syntax, make sure to include the nested quotes (`"'` and `'"`) around the language and framework names. (If you leave out the inner quotes, Angular will read them as a variable names, rather than strings, which will cause errors. All un-bracketed attributes, however, are automatically read as strings, so they don't need inner quotes.)
346
+
347
+ #### Single-input mode
348
+
349
+ You may also combine all your inputs into one compound object and include it as a `form` input, like so:
350
+
351
+
352
+ ```javascript
353
+ const yourCompoundInputObject = {
354
+ schema: { ... }, // REQUIRED
355
+ layout: [ ... ], // optional
356
+ data: { ... }, // optional
357
+ options: { ... }, // optional
358
+ widgets: { ... }, // optional
359
+ language: '...' , // optional
360
+ framework: '...' // (or { ... }) optional
361
+ }
362
+ ```
363
+ ```html
364
+ <json-schema-form
365
+ [form]="yourCompoundInputObject"
366
+ (onSubmit)="yourOnSubmitFn($event)">
367
+ </json-schema-form>
368
+ ```
369
+
370
+ You can also mix these two styles depending on your needs. In the example playground, all examples use the combined `form` input for `schema`, `layout`, and `data`, which enables each example to control those three inputs, but the playground uses separate inputs for `language` and `framework`, enabling it to change those settings independent of the example.
371
+
372
+ Combining inputs is useful if you have many unique forms and store each form's data and schema together. If you have one form (or many identical forms), it will likely be more useful to use separate inputs for your data and schema. Though even in that case, if you use a custom layout, you could store your schema and layout together and use one input for both.
373
+
374
+ #### Compatibility modes
375
+
376
+ If you have previously used another JSON form creation library—Angular Schema Form (for AngularJS), React JSON Schema Form, or JSON Form (for jQuery)—in order to make the transition easier, Angular JSON Schema Form will recognize the input names and custom input objects used by those libraries. It should automatically work with JSON Schemas in [version 6](http://json-schema.org/draft-06/schema), [version 4](http://json-schema.org/draft-04/schema), [version 3](http://json-schema.org/draft-03/schema), or the [truncated version 3 format supported by JSON Form](https://github.com/joshfire/jsonform/wiki#schema-shortcut). So the following will all work:
377
+
378
+ Angular Schema Form (AngularJS) compatibility:
379
+
380
+
381
+ ```html
382
+ <json-schema-form
383
+ [schema]="yourJsonSchema"
384
+ [form]="yourAngularSchemaFormLayout"
385
+ [(model)]="yourData">
386
+ </json-schema-form>
387
+ ```
388
+
389
+ React JSON Schema Form compatibility:
390
+
391
+
392
+ ```html
393
+ <json-schema-form
394
+ [schema]="yourJsonSchema"
395
+ [UISchema]="yourReactJsonSchemaFormUISchema"
396
+ [(formData)]="yourData">
397
+ </json-schema-form>
398
+ ```
399
+
400
+ JSON Form (jQuery) compatibility:
401
+
402
+
403
+ ```html
404
+ <json-schema-form
405
+ [form]="{
406
+ schema: yourJsonSchema,
407
+ form: yourJsonFormLayout,
408
+ customFormItems: yourJsonFormCustomFormItems,
409
+ value: yourData
410
+ }">
411
+ </json-schema-form>
412
+ ```
413
+
414
+ Note: 2-way data binding will work with any dedicated data input, including 'data', 'model', 'ngModel', or 'formData'. However, 2-way binding will _not_ work with the combined 'form' input.
415
+
416
+ #### Debugging inputs and outputs
417
+
418
+ Finally, Angular JSON Schema Form includes some additional inputs and outputs for debugging:
419
+
420
+ * `debug` input — Activates debugging mode.
421
+
422
+
423
+ * `loadExternalAssets` input — Causes external JavaScript and CSS needed by the selected framework to be automatically loaded from a CDN (this is not 100% reliable, so while this can be helpful during development and testing, it is not recommended for production)—Note: If you are using this mode and get a console error saying an external asset has not loaded (such as jQuery, required for Bootstrap 3) simply reloading your web browser will usually fix it.
424
+
425
+
426
+ * `formSchema` and `formLayout` outputs — Returns the final schema and layout used to create the form (which will either show how your original input schema and layout were modified, if you provided inputs, or show you the automatically generated ones, if you didn't).
427
+
428
+
429
+ ```html
430
+ <json-schema-form
431
+ [schema]="yourJsonSchema"
432
+ [debug]="true"
433
+ loadExternalAssets="true"
434
+ (formSchema)="showFormSchemaFn($event)"
435
+ (formLayout)="showFormLayoutFn($event)">
436
+ </json-schema-form>
437
+ ```
438
+
439
+ ## Customizing
440
+
441
+ In addition to a large number of user-settable options, Angular JSON Schema Form also has the ability to load custom form control widgets and layout frameworks. All forms are constructed from these basic components. The default widget library includes all standard HTML 5 form controls, as well as several common layout patterns, such as multiple checkboxes and tab sets. The default framework library includes templates to style forms using Material Design, Bootstrap 3, or Bootstrap 4 (or plain HTML with no formatting, which is not useful in production, but can be helpful for development and debugging).
442
+
443
+ ### User settings
444
+
445
+ (TODO: List all available user settings, and configuration options for each.)
446
+
447
+ ### Creating custom input validation error messages
448
+
449
+ You can easily add your own custom input validation error messages, either for individual control widgets, or for your entire form.
450
+
451
+ #### Setting error messages for individual controls or the entire form
452
+
453
+ To set messages for individual form controls, add them to that control's node in the form layout, like this:
454
+
455
+
456
+ ```javascript
457
+ const yourFormLayout = [
458
+ { key: 'name',
459
+ title: 'Enter your name',
460
+ validationMessages: {
461
+ // Put your error messages for the 'name' field here
462
+ }
463
+ },
464
+ { type: 'submit', title: 'Submit' }
465
+ ]
466
+ ```
467
+
468
+ To set messages for the entire form, add them to the form options, inside the defautWidgetOptions validationMessages object, like this:
469
+
470
+
471
+ ```javascript
472
+ const yourFormOptions = {
473
+ defautWidgetOptions: {
474
+ validationMessages: {
475
+ // Put your error messages for the entire form here
476
+ }
477
+ }
478
+ }
479
+ ```
480
+
481
+ #### How to format error messages
482
+
483
+ The validationMessages object—in either a layout node or the form options—contains the names of each error message you want to set as keys, and the corresponding messages as values. Messages may be in any of the following formats:
484
+
485
+ * String: A plain text message, which is always the same.
486
+
487
+
488
+ * String template: A text message that includes Angular template-style {{variables}}, which will be be replaced with values from the returned error object.
489
+
490
+
491
+ * Function: A JavaScript function which accepts the error object as input, and returns a string error message.
492
+
493
+ Here are examples of all three error message types:
494
+
495
+
496
+ ```javascript
497
+ validationMessages: {
498
+ // String error message
499
+ required: 'This field is required.',
500
+ // String template error message
501
+ // - minimumLength variable will be replaced
502
+ minLength: 'Must be at least {{minimumLength}} characters long.',
503
+ // Function error message
504
+ // - example error object: { multipleOfValue: 0.01, currentValue: 3.456 }
505
+ // - resulting error message: 'Must have 2 or fewer decimal places.'
506
+ multipleOf: function(error) {
507
+ if ((1 / error.multipleOfValue) % 10 === 0) {
508
+ const decimals = Math.log10(1 / error.multipleOfValue);
509
+ return `Must have ${decimals} or fewer decimal places.`;
510
+ } else {
511
+ return `Must be a multiple of ${error.multipleOfValue}.`;
512
+ }
513
+ }
514
+ }
515
+
516
+ ```
517
+ (Note: These examples are from the default set of built-in error messages, which includes messages for all JSON Schema errors except type, const, enum, and dependencies.)
518
+
519
+ #### Available input validation errors and object values
520
+
521
+ Here is a list of all the built-in JSON Schema errors, which data type each error is available for, and the values in their returned error objects:
522
+
523
+ Error name | Data type | Returned error object values
524
+ -----------------|-----------|-----------------------------------------
525
+ required | any | (none)
526
+ type | any | requiredType, currentValue
527
+ const | any | requiredValue, currentValue
528
+ enum | any | allowedValues, currentValue
529
+ minLength | string | minimumLength, currentLength
530
+ maxLength | string | maximumLength, currentLength
531
+ pattern | string | requiredPattern, currentValue
532
+ format | string | requiredFormat, currentValue
533
+ minimum | number | minimumValue, currentValue
534
+ exclusiveMinimum | number | exclusiveMinimumValue, currentValue
535
+ maximum | number | maximumValue, currentValue
536
+ exclusiveMaximum | number | exclusiveMaximumValue, currentValue
537
+ multipleOf | number | multipleOfValue, currentValue
538
+ minProperties | object | minimumProperties, currentProperties
539
+ maxProperties | object | maximumProperties, currentProperties
540
+ dependencies * | object | (varies, based on dependencies schema)
541
+ minItems | array | minimumItems, currentItems
542
+ maxItems | array | maximumItems, currentItems
543
+ uniqueItems | array | duplicateItems
544
+ contains * | array | requiredItem
545
+
546
+ * Note: The `contains` and `dependencies` validators are still in development, and do not yet work correctly.
547
+
548
+ ### Changing or adding widgets
549
+
550
+ To add a new widget or override an existing widget, either add an object containing your new widgets to the `widgets` input of the `<json-schema-form>` tag, or load the `WidgetLibraryService` and call `registerWidget(widgetType, widgetComponent)`, with a string type name and an Angular component to be used whenever a form needs that widget type.
551
+
552
+ Example:
553
+
554
+
555
+ ```javascript
556
+ import { YourInputWidgetComponent } from './your-input-widget.component';
557
+
558
+ import { YourCustomWidgetComponent } from './your-custom-widget.component';
559
+
560
+ ...
561
+
562
+ const yourNewWidgets = {
563
+ 'input': YourInputWidgetComponent, // Replace existing 'input' widget
564
+ 'custom-control': YourCustomWidgetComponent // Add new 'custom-control' widget
565
+ }
566
+ ```
567
+
568
+ ...and...
569
+
570
+
571
+ ```html
572
+ <json-schema-form
573
+ [schema]="yourJsonSchema"
574
+ [widgets]="yourNewWidgets">
575
+ </json-schema-form>
576
+ ```
577
+
578
+ ...or...
579
+
580
+
581
+ ```javascript
582
+
583
+ import { WidgetLibraryService } from '@ng-formworks/core';
584
+
585
+
586
+ ...
587
+
588
+ constructor(private widgetLibrary: WidgetLibraryService) { }
589
+
590
+ ...
591
+
592
+ // Replace existing 'input' widget:
593
+ widgetLibrary.registerWidget('input', YourInputWidgetComponent);
594
+
595
+ // Add new 'custom-control' widget:
596
+ widgetLibrary.registerWidget('custom-control', YourCustomWidgetComponent);
597
+ ```
598
+
599
+ To see many examples of widgets, explore the source code, or call `getAllWidgets()` from the `WidgetLibraryService` to see all widgets currently available in the library. All default widget components are in the `projects/json-schema-form/src/lib/widget-library` folder, and all custom Material Design widget components are in the `projects/json-schema-form/src/lib/framework-library/material-design-framework` folder. (The Bootstrap 3 and Bootstrap 4 frameworks just reformat the default widgets, and so do not include any custom widgets of their own.)
600
+
601
+ ### Changing or adding frameworks
602
+
603
+ To change the active framework, either use the `framework` input of the `<json-schema-form>` tag, or load the `FrameworkLibraryService` and call `setFramework(yourCustomFramework)`, with either the name of an available framework ('bootstrap-3', 'bootstrap-4', 'material-design', or 'no-framework'), or with your own custom framework object, like so:
604
+
605
+
606
+ ```javascript
607
+ import { YourFrameworkComponent } from './your-framework.component';
608
+ import { YourWidgetComponent } from './your-widget.component';
609
+
610
+ ...
611
+
612
+ const yourCustomFramework = {
613
+ framework: YourFrameworkComponent, // required
614
+ widgets: { 'your-widget-name': YourWidgetComponent, ... }, // optional
615
+ stylesheets: [ '//url-to-framework-external-style-sheet', ... ], // optional
616
+ scripts: [ '//url-to-framework-external-script', ... ] // optional
617
+
618
+ }
619
+ ```
620
+
621
+ ...and...
622
+
623
+
624
+ ```html
625
+ <json-schema-form
626
+ [schema]="yourJsonSchema"
627
+ [framework]="yourCustomFramework">
628
+ </json-schema-form>
629
+ ```
630
+
631
+ ...or...
632
+
633
+
634
+ ```javascript
635
+ import { FrameworkLibraryService } from '@ng-formworks/core';
636
+
637
+ ...
638
+
639
+ constructor(private frameworkLibrary: FrameworkLibraryService) { }
640
+
641
+ ...
642
+
643
+ frameworkLibrary.setFramework(yourCustomFramework);
644
+ ```
645
+
646
+ The value of the required `framework` key is an Angular component which will be called to format each widget before it is displayed. The optional `widgets` object contains any custom widgets, which will override or supplement the built-in widgets. And the optional `stylesheets` and `scripts` arrays contain URLs to any additional external style sheets or JavaScript libraries required by the framework. These are the external stylesheets and scripts that will be loaded if the "loadExternalAssets" option is set to "true".
647
+
648
+ #### Loading external assets required by a framework
649
+
650
+ Most Web layout framework libraries (including both Bootstrap and Material Design) need additional external JavaScript and/or CSS assets loaded in order to work properly. The best practice is to load these assets separately in your site, before calling Angular JSON Schema Form. (For the included libraries, follow these links for more information about how to do this: [Bootstrap](http://getbootstrap.com/getting-started/) and [Material Design](https://github.com/angular/material2/blob/master/GETTING_STARTED.md).)
651
+
652
+ Alternately, during development, you may find it helpful to let Angular JSON Schema Form load these resources for you (as wed did in the 'Basic use' example, above), which you can do in several ways:
653
+
654
+ * Call `setFramework` with a second parameter of `true` (e.g. `setFramework('material-design', true)`), or
655
+
656
+
657
+ * Add `loadExternalAssets: true` to your `options` object, or
658
+
659
+
660
+ * Add `loadExternalAssets="true"` to your `<json-schema-form>` tag, as shown above
661
+
662
+ Finally, if you want to see what scripts a particular framework will automatically load, after setting that framework you can call `getFrameworkStylesheets()` or `getFrameworkScritps()` from the `FrameworkLibraryService` to return the built-in arrays of URLs.
663
+
664
+ However, if you are creating a production site you should load these assets separately, and make sure to remove all references to `loadExternalAssets` to prevent the assets from being loaded twice.
665
+
666
+ #### Theming
667
+
668
+
669
+ Framework specific theming is supported(implementation dependent).
670
+
671
+
672
+ To enable theming in a form component, the theme binding must be in place
673
+
674
+
675
+ for example
676
+
677
+
678
+ ```html
679
+ <json-schema-form
680
+ loadExternalAssets="true"
681
+ [schema]="yourJsonSchema"
682
+ [framework]="yourFramework"
683
+ [theme]="yourTheme"
684
+ (onSubmit)="yourOnSubmitFn($event)">
685
+ </json-schema-form>
686
+ ```
687
+
688
+ currently the following built-in themes are available(per framework):
689
+
690
+ * Bootstrap 3:"bootstrap3_default"
691
+ * Bootstrap 4:"bootstrap4_default"
692
+ * Bootstrap 5:"bootstrap5_default" | "light" | "dark"
693
+ * Material design:"material_default" | "indigo-pink" | "purple-green" | "deeppurple-amber" | "pink-bluegrey"
694
+ * DaisyUi: "daisyui_default" | "light" | "dark" | "cupcake" | "cmyk" | "pastel" |"daisyui_leaf"
695
+
696
+ | Framework Values | Theme values |
697
+ |--|--|
698
+ | "bootstrap-3" | "bootstrap3_default" |
699
+ | "bootstrap-4" | "bootstrap4_default" |
700
+ | "bootstrap-5" | "light" |
701
+ | | "dark" |
702
+ | "material-design" | "material_default" |
703
+ | | "indigo-pink" |
704
+ | | "purple-green" |
705
+ | | "deeppurple-amber" |
706
+ | | "pink-bluegrey" |
707
+ | "daisyui" | "daisyui_default" |
708
+ | | "light" |
709
+ | | "dark" |
710
+ | | "cupcake" |
711
+ | | "pastel" |
712
+ | | "daisyui-leaf" |
713
+
714
+
715
+ for more on how to customize themes, take a look at the relevant framework's docs:
716
+
717
+ * [`@ng-formworks/bootstrap3`](./projects/ng-formworks-bootstrap3/README.md#custom-theming)
718
+
719
+ * [`@ng-formworks/bootstrap4`](./projects/ng-formworks-bootstrap3/README.md#custom-theming)
720
+
721
+
722
+ * [`@ng-formworks/bootstrap5`](./projects/ng-formworks-bootstrap4/README.md#custom-theming)
723
+
724
+
725
+ * [`@ng-formworks/daisyui`](./projects/ng-formworks-daisyui/README.md#custom-theming)
726
+
727
+
728
+ * [`@ng-formworks/material`](./projects/ng-formworks-material/README.md#custom-theming)
729
+
730
+ ## contributing guide
731
+
732
+ If you like this project and want to contribute you can check this [documentation](./CONTRIBUTING.md).
733
+
734
+ ## License
735
+
736
+ [MIT](/LICENSE)
737
+
738
+ [gh_core_project]:./README.md
739
+
740
+ [npm_core_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fcore.svg?color=#010101
741
+
742
+ [npm_core_ver]:https://www.npmjs.com/package/@ng-formworks/core
743
+
744
+ [npm_core_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fcore/RC.svg?color=blue
745
+
746
+ [npm_core_ver_RC]:https://www.npmjs.com/package/@ng-formworks/core
747
+
748
+ [npm_core_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fcore/alpha.svg?color=blue
749
+
750
+ [npm_core_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/core
751
+
752
+ [gh_cssframework_project]:./projects/ng-formworks-cssframework/README.md
753
+
754
+ [npm_cssframework_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fcssframework.svg?color=#010101
755
+
756
+ [npm_cssframework_ver]:https://www.npmjs.com/package/@ng-formworks/cssframework
757
+
758
+ [npm_cssframework_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fcssframework/RC.svg?color=blue
759
+
760
+ [npm_cssframework_ver_RC]:https://www.npmjs.com/package/@ng-formworks/cssframework
761
+
762
+ [npm_cssframework_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fcssframework/alpha.svg?color=blue
763
+
764
+ [npm_cssframework_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/cssframework
765
+
766
+ [gh_bootstrap3_project]:./projects/ng-formworks-bootstrap3/README.md
767
+
768
+ [npm_bootstrap3_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap3.svg?color=#010101
769
+
770
+ [npm_bootstrap3_ver]:https://www.npmjs.com/package/@ng-formworks/bootstrap3
771
+
772
+ [npm_bootstrap3_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap3/RC.svg?color=blue
773
+
774
+ [npm_bootstrap3_ver_RC]:https://www.npmjs.com/package/@ng-formworks/bootstrap3
775
+
776
+ [npm_bootstrap3_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap3/alpha.svg?color=blue
777
+
778
+ [npm_bootstrap3_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/bootstrap3
779
+
780
+ [gh_bootstrap4_project]:./projects/ng-formworks-bootstrap4/README.md
781
+
782
+ [npm_bootstrap4_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap4.svg?color=#010101
783
+
784
+ [npm_bootstrap4_ver]:https://www.npmjs.com/package/@ng-formworks/bootstrap4
785
+
786
+ [npm_bootstrap4_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap4/RC.svg?color=blue
787
+
788
+ [npm_bootstrap4_ver_RC]:https://www.npmjs.com/package/@ng-formworks/bootstrap4
789
+
790
+ [npm_bootstrap4_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap4/alpha.svg?color=blue
791
+
792
+ [npm_bootstrap4_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/bootstrap4
793
+
794
+ [gh_bootstrap5_project]:./projects/ng-formworks-bootstrap5/README.md
795
+
796
+ [npm_bootstrap5_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap5.svg?color=#010101
797
+
798
+ [npm_bootstrap5_ver]:https://www.npmjs.com/package/@ng-formworks/bootstrap5
799
+
800
+ [npm_bootstrap5_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap5/RC.svg?color=blue
801
+
802
+ [npm_bootstrap5_ver_RC]:https://www.npmjs.com/package/@ng-formworks/bootstrap5
803
+
804
+ [npm_bootstrap5_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fbootstrap5/alpha.svg?color=blue
805
+
806
+ [npm_bootstrap5_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/bootstrap5
807
+
808
+ [gh_daisyui_project]:./projects/ng-formworks-daisyui/README.md
809
+
810
+ [npm_daisyui_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fdaisyui.svg?color=#010101
811
+
812
+ [npm_daisyui_ver]:https://www.npmjs.com/package/@ng-formworks/daisyui
813
+
814
+ [npm_daisyui_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fdaisyui/RC.svg?color=blue
815
+
816
+ [npm_daisyui_ver_RC]:https://www.npmjs.com/package/@ng-formworks/daisyui
817
+
818
+ [npm_daisyui_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fdaisyui/alpha.svg?color=blue
819
+
820
+ [npm_daisyui_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/daisyui
821
+
822
+ [gh_material_project]:./projects/ng-formworks-material/README.md
823
+
824
+ [npm_material_badge]:https://img.shields.io/npm/v/%40ng-formworks%2Fmaterial.svg?color=#010101
825
+
826
+ [npm_material_ver]:https://www.npmjs.com/package/@ng-formworks/material
827
+
828
+ [npm_material_badge_RC]:https://img.shields.io/npm/v/%40ng-formworks%2Fmaterial/RC.svg?color=blue
829
+
830
+ [npm_material_ver_RC]:https://www.npmjs.com/package/@ng-formworks/material
831
+
832
+ [npm_material_badge_alpha]:https://img.shields.io/npm/v/%40ng-formworks%2Fmaterial/alpha.svg?color=blue
833
+
834
+ [npm_material_ver_alpha]:https://www.npmjs.com/package/@ng-formworks/material