You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-54Lines changed: 35 additions & 54 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Note: This is currently a personal proof-of-concept project, and is NOT affiliat
15
15
16
16
[Check out some examples here.](https://angular2-json-schema-form.firebaseapp.com/)
17
17
18
-
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 or Bootstrap 3, or without any formatting.
18
+
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, or without any formatting.
19
19
20
20
## Installation
21
21
@@ -48,71 +48,48 @@ If you want detailed documentation describing the individual functions used in t
48
48
If, after playing with the examples, you decide this library is functional enough to use in your own project, you can [install it from NPM](https://www.npmjs.com/package/angular2-json-schema-form) using either [NPM](https://www.npmjs.com) or [Yarn](https://yarnpkg.com). To install with NPM, run the following from your terminal:
49
49
50
50
```shell
51
-
npm install angular2-json-schema-form --save
52
-
npm install @angular/cdk --save
53
-
npm install @angular/flex-layout --save
54
-
npm install @angular/material --save
51
+
npm install angular2-json-schema-form
55
52
```
56
53
57
-
IMPORTANT NOTE ABOUT PEER DEPENDANCIES: For now, Angular Material is a required peer dependency for the current version. This will be fixed in a future version, which will offer separate installers for the Bootstrap and Material Design frameworks. But until that happens, even if you don't intend to use Material Design framework, you will need to install Angular Material and its related modules through NPM for your project to build correctly.
58
-
59
-
Then import JsonSchemaFormModule in your main application module:
(For information about which Angular Material modules to import, check the [Angular Material site](https://material.angular.io/guide/getting-started).)
73
-
74
-
If you don't want to use the Material Design framework, you don't need to import these modules. (To get the project to build correctly, you need to install the Angular Material libraries through NPM, as described above, but you don't need to actually import them.)
75
-
76
-
Finally, edit the `imports` array in your @NgModule declaration to add `JsonSchemaFormModule`, and, optionally, the Angular Material modules.
77
-
78
-
Your final app.module.ts should look something like this:
54
+
Then import JsonSchemaFormModule in your main application module, like this:
For complete examples of how to install and configure Angular JSON Schema Form to work with each included display framework, check out the following seed applications:
76
+
77
+
*[Angular JSON Schema Form Material Design Seed App](https://github.com/dschnelldavis/ng-jsf-material-design-seed)
78
+
*[Angular JSON Schema Form Bootstrap 3 Seed App](https://github.com/dschnelldavis/ng-jsf-bootstrap3-seed)
79
+
*[Angular JSON Schema Form Bootstrap 4 Seed App](https://github.com/dschnelldavis/ng-jsf-bootstrap4-seed)
80
+
101
81
#### Additional notes for Angular CLI
102
82
103
83
Make sure you are running the latest version of Angular CLI.
104
84
105
-
Older versions of Angular CLI (e.g. 1.0.1) may fail with the error `Critical dependency: the request of a dependency is an expression` while trying to compile ajv (Another JSON Schema Validator). But this error has been fixed in newer versions. So if you receive that error, just upgrade your Angular CLI to the latest version.
85
+
Older versions of Angular CLI (e.g. 1.0.1) may fail with the error `Critical dependency: the request of a dependency is an expression` while trying to compile ajv (Another JSON Schema Validator). But this error has been fixed in newer versions. So if you receive that error, upgrade your Angular CLI to the latest version.
106
86
107
87
#### Additional notes for SystemJS
108
88
109
89
If you use SystemJS, you will also need to make the following changes to your systemjs.config.js file. (If you're using a recent version of Angular CLI, or you don't have a systemjs.config.js file in your project, that means you're not using SystemJS, and you can safely ignore this section.)
110
90
111
-
Add these lines to the 'map' section of systemjs.config.js, if they do not already exist:
91
+
Add these lines to the 'map' section of systemjs.config.js:
@@ -122,23 +99,29 @@ Add these lines to the 'map' section of systemjs.config.js, if they do not alrea
122
99
123
100
### Basic use
124
101
125
-
For basic use, after loading the JsonSchemaFormModule as described above, to add a form to your Angular component, simply add the following to your component's template:
102
+
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:
126
103
127
104
```html
128
105
<json-schema-form
106
+
framework="bootstrap-3"
107
+
loadExternalAssets="true"
129
108
[schema]="yourJsonSchema"
130
109
(onSubmit)="yourOnSubmitFn($event)">
131
110
</json-schema-form>
132
111
```
133
112
134
-
Where the `schema` input is a valid JSON schema object (v3 or v4), and the `onSubmit` output calls a function to process the submitted form data, which will be passed as a JSON object. If you don't already have your own schemas, you can find a whole bunch of samples to test with in the `src/demo/assets/example-schemas` folder, as described above.
113
+
Where the `framework` is the name of the display framework to use (`bootstrap-3`, `bootstrap-4`, `material-design`, or `no-framework`), `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 `src/demo/assets/example-schemas` folder, as described above.
114
+
115
+
(Note: 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 should be removed in production sites, which should instead load all required assets separately. For full details see 'Changing or adding frameworks', below.)
135
116
136
117
### Data-only mode
137
118
138
119
Angular JSON Schema Form can also create a form entirely from a JSON object—with no schema—like so:
139
120
140
121
```html
141
122
<json-schema-form
123
+
framework="bootstrap-4"
124
+
loadExternalAssets="true"
142
125
[(ngModel)]="exampleJsonObject">
143
126
</json-schema-form>
144
127
```
@@ -161,7 +144,7 @@ In this mode, Angular JSON Schema Form automatically generates a schema from you
161
144
162
145
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.
163
146
164
-
Also, notice that the 'ngModel' input supports Angular's 2-way data binding, just like other form controls, which is why an onSubmit function was not necessary (though onSubmit is still available for you to add if you want).
147
+
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.
165
148
166
149
### Advanced use
167
150
@@ -174,8 +157,8 @@ For more control over your form, you may provide these additional inputs:
174
157
*`options` - object to set any global options for the form
175
158
*`widgets` to add custom widgets
176
159
*`framework` - string or object to set which framework to use
177
-
set to 'material-design' (the default), 'bootstrap-3', 'no-framework',
178
-
or pass in your own custom framework object
160
+
set to 'bootstrap-3', 'bootstrap-4', 'material-design', or
161
+
'no-framework' (the default), or pass in your own custom framework object
179
162
180
163
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.
181
164
@@ -188,7 +171,7 @@ Here is an example:
188
171
[(data)]="yourData"
189
172
[options]="yourFormOptions"
190
173
[widgets]="yourCustomWidgets"
191
-
framework="bootstrap-3"
174
+
framework="material-design"
192
175
loadExternalAssets="true"
193
176
(onChanges)="yourOnChangesFn($event)"
194
177
(onSubmit)="yourOnSubmitFn($event)"
@@ -197,8 +180,6 @@ Here is an example:
197
180
</json-schema-form>
198
181
```
199
182
200
-
(Note: The `loadExternalAssets` attribute may be useful when you are first trying out this library, but do not use it in production sites - instead separately load any required assets. For full details see 'Changing or adding frameworks', below.)
201
-
202
183
#### Single-input mode
203
184
204
185
You may also combine all your inputs into one compound object and include it as a `form` input, like so:
@@ -221,7 +202,7 @@ let yourCompoundInputObject = {
221
202
</json-schema-form>
222
203
```
223
204
224
-
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 another input for `framework`, enabling you to change the framework separately from the example.
205
+
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 another input for `framework`, enabling you to change the framework independent of the example.
225
206
226
207
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.
227
208
@@ -261,7 +242,7 @@ JSON Form (jQuery) compatibility:
261
242
262
243
Note: 2-way data binding will work with any dedicated data input,
263
244
including 'data', 'model', 'ngModel', or 'formData'.
264
-
But 2-way binding will not work with the combined 'form' input.
245
+
However, 2-way binding will _not_ work with the combined 'form' input.
265
246
266
247
#### Debugging inputs and outputs
267
248
@@ -275,15 +256,15 @@ Finally, Angular JSON Schema Form includes some additional inputs and outputs fo
275
256
<json-schema-form
276
257
[schema]="yourJsonSchema"
277
258
[debug]="true"
278
-
[loadExternalAssets]="true"
259
+
loadExternalAssets="true"
279
260
(formSchema)="showFormSchemaFn($event)"
280
261
(formLayout)="showFormLayoutFn($event)">
281
262
</json-schema-form>
282
263
```
283
264
284
265
## Customizing
285
266
286
-
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 either Bootstrap 3 or Material Design (or plain HTML with no formatting, which is not useful in production, but can be helpful for development and debugging).
267
+
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).
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 `/src/lib/src/widget-library` folder, and all custom Material Design widget components are in the `/src/lib/src/framework-library/material-design-framework` folder. (The Bootstrap 3 framework just reformats the default widgets, and so does not include any custom widgets if its own.)
402
+
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 `/src/lib/src/widget-library` folder, and all custom Material Design widget components are in the `/src/lib/src/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.)
422
403
423
404
### Changing or adding frameworks
424
405
425
-
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 (by default 'material-design', 'bootstrap-3' or 'no-framework'), or with your own custom framework object in the following format:
406
+
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:
@@ -469,7 +450,7 @@ However, if you are creating a production site you should load these assets sepa
469
450
470
451
#### Two approaches to writing your own frameworks
471
452
472
-
The two built-in frameworks (in the `/src/lib/src/framework-library` folder) demonstrate different strategies for how frameworks can style form elements. The Bootstrap 3 framework is very lightweight and includes no additional widgets (though it does load some external stylesheets and scripts). It works entirely by adding styles to the default widgets. In contrast, the Material Design framework uses the [Material Design for Angular](https://material.angular.io) library to replace most of the default form control widgets with custom widgets from that library.
453
+
The two built-in frameworks (in the `/src/lib/src/framework-library` folder) demonstrate different strategies for how frameworks can style form elements. The Bootstrap 3 and Bootstrap 4 frameworks are very lightweight and include no additional widgets (though they do load some external stylesheets and scripts). They work entirely by adding styles to the default widgets. In contrast, the Material Design framework uses the [Material Design for Angular](https://material.angular.io) library to replace most of the default form control widgets with custom widgets from that library.
473
454
474
455
## Contributions and future development
475
456
@@ -483,7 +464,7 @@ This library is mostly functional (I'm already using it in another large site, w
483
464
484
465
* TDD tests—The single biggest flaw in this library is that each change or improvement has the potential to break something else (which has already happened several times). Integrating automated tests into the build process would fix that.
485
466
486
-
* More frameworks—Not everyone uses Material Design or Bootstrap 3, so it would be great to create framework plug-ins for [Bootstrap 4](https://github.com/ng-bootstrap/ng-bootstrap), [Foundation 6](https://github.com/zurb/foundation-sites), [Semantic UI](https://github.com/vladotesanovic/ngSemantic), or other web design frameworks.
467
+
* More frameworks—Not everyone uses Material Design, Bootstrap 3, or [Bootstrap 4](https://github.com/ng-bootstrap/ng-bootstrap), so it would be great to create framework plug-ins for[Foundation 6](https://github.com/zurb/foundation-sites), [Semantic UI](https://github.com/vladotesanovic/ngSemantic), or other web design frameworks.
487
468
488
469
* More widgets—There are lots of great form controls available, such as the [Pikaday calendar](https://github.com/dbushell/Pikaday), [Spectrum color picker](http://bgrins.github.io/spectrum), and [ACE code editor](https://ace.c9.io), which just need small custom wrappers to convert them into Angular JSON Schema Form plug-ins. In addition, there are a few additional features of HTML, JSON Schema, and Material Design which could be fixed by adding new widgets:
0 commit comments