Skip to content

Commit 9397c85

Browse files
committed
Update readme. Add links to framework demonstration seed apps.
1 parent c411bfd commit 9397c85

File tree

3 files changed

+37
-57
lines changed

3 files changed

+37
-57
lines changed

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
The MIT License
2-
3-
Copyright (c) 2014-2016 Google, Inc.
2+
Copyright (c) 2014-2016 David Schnell-Davis
43

54
Permission is hereby granted, free of charge, to any person obtaining a copy
65
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Note: This is currently a personal proof-of-concept project, and is NOT affiliat
1515

1616
[Check out some examples here.](https://angular2-json-schema-form.firebaseapp.com/)
1717

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.
1919

2020
## Installation
2121

@@ -48,71 +48,48 @@ If you want detailed documentation describing the individual functions used in t
4848
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:
4949

5050
```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
5552
```
5653

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:
60-
61-
```javascript
62-
import { JsonSchemaFormModule } from 'angular2-json-schema-form';
63-
```
64-
65-
If you want to use the Angular Material Design framework, also add:
66-
67-
```javascript
68-
import { FlexLayoutModule } from '@angular/flex-layout';
69-
import { MatInputModule, MatSelectModule } from '@angular/material';
70-
```
71-
72-
(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:
7955

8056
```javascript
8157
import { BrowserModule } from '@angular/platform-browser';
8258
import { NgModule } from '@angular/core';
83-
import { FlexLayoutModule } from '@angular/flex-layout';
84-
import { MatInputModule, MatSelectModule } from '@angular/material';
8559

8660
import { JsonSchemaFormModule } from 'angular2-json-schema-form';
8761

8862
import { AppComponent } from './app.component';
8963

9064
@NgModule({
9165
declarations: [ AppComponent ],
92-
imports: [
93-
BrowserModule, FlexLayoutModule, MatInputModule, MatSelectModule, JsonSchemaFormModule
94-
],
66+
imports: [ BrowserModule, JsonSchemaFormModule ],
9567
providers: [],
9668
bootstrap: [ AppComponent ]
9769
})
9870
export class AppModule { }
9971
```
10072

73+
#### Seed Application Examples
74+
75+
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+
10181
#### Additional notes for Angular CLI
10282

10383
Make sure you are running the latest version of Angular CLI.
10484

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.
10686

10787
#### Additional notes for SystemJS
10888

10989
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.)
11090

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:
11292
```javascript
113-
'@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
114-
'@angular/cdk': 'npm:@angular/cdk/bundles/cdk.umd.js',
115-
'@angular/material': 'npm:@angular/material/bundles/material.umd.js',
11693
'angular2-json-schema-form': 'npm:angular2-json-schema-form/bundles/angular2-json-schema-form.umd.js',
11794
'ajv': 'npm:ajv/dist/ajv.min.js',
11895
'lodash': 'npm:lodash/lodash.min.js'
@@ -122,23 +99,29 @@ Add these lines to the 'map' section of systemjs.config.js, if they do not alrea
12299

123100
### Basic use
124101

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:
126103

127104
```html
128105
<json-schema-form
106+
framework="bootstrap-3"
107+
loadExternalAssets="true"
129108
[schema]="yourJsonSchema"
130109
(onSubmit)="yourOnSubmitFn($event)">
131110
</json-schema-form>
132111
```
133112

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.)
135116

136117
### Data-only mode
137118

138119
Angular JSON Schema Form can also create a form entirely from a JSON object—with no schema—like so:
139120

140121
```html
141122
<json-schema-form
123+
framework="bootstrap-4"
124+
loadExternalAssets="true"
142125
[(ngModel)]="exampleJsonObject">
143126
</json-schema-form>
144127
```
@@ -161,7 +144,7 @@ In this mode, Angular JSON Schema Form automatically generates a schema from you
161144

162145
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.
163146

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.
165148

166149
### Advanced use
167150

@@ -174,8 +157,8 @@ For more control over your form, you may provide these additional inputs:
174157
* `options` - object to set any global options for the form
175158
* `widgets` to add custom widgets
176159
* `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
179162

180163
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.
181164

@@ -188,7 +171,7 @@ Here is an example:
188171
[(data)]="yourData"
189172
[options]="yourFormOptions"
190173
[widgets]="yourCustomWidgets"
191-
framework="bootstrap-3"
174+
framework="material-design"
192175
loadExternalAssets="true"
193176
(onChanges)="yourOnChangesFn($event)"
194177
(onSubmit)="yourOnSubmitFn($event)"
@@ -197,8 +180,6 @@ Here is an example:
197180
</json-schema-form>
198181
```
199182

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-
202183
#### Single-input mode
203184

204185
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 = {
221202
</json-schema-form>
222203
```
223204

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.
225206

226207
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.
227208

@@ -261,7 +242,7 @@ JSON Form (jQuery) compatibility:
261242

262243
Note: 2-way data binding will work with any dedicated data input,
263244
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.
265246

266247
#### Debugging inputs and outputs
267248

@@ -275,15 +256,15 @@ Finally, Angular JSON Schema Form includes some additional inputs and outputs fo
275256
<json-schema-form
276257
[schema]="yourJsonSchema"
277258
[debug]="true"
278-
[loadExternalAssets]="true"
259+
loadExternalAssets="true"
279260
(formSchema)="showFormSchemaFn($event)"
280261
(formLayout)="showFormLayoutFn($event)">
281262
</json-schema-form>
282263
```
283264

284265
## Customizing
285266

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).
287268

288269
### User settings
289270

@@ -380,7 +361,7 @@ maxProperties | object | maximumProperties, currentProperties
380361
minItems | array | minimumItems, currentItems
381362
maxItems | array | maximumItems, currentItems
382363
uniqueItems | array | duplicateItems
383-
contains * | array | requiredItem, currentItems
364+
contains * | array | requiredItem
384365

385366
* Note: The contains and dependencies validators are still in development, and do not yet work correctly.
386367

@@ -418,11 +399,11 @@ widgetLibrary.registerWidget('input', YourInputWidgetComponent);
418399
widgetLibrary.registerWidget('custom-control', YourCustomWidgetComponent);
419400
```
420401

421-
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.)
422403

423404
### Changing or adding frameworks
424405

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:
426407

427408
```javascript
428409
import { YourFrameworkComponent } from './your-framework.component';
@@ -469,7 +450,7 @@ However, if you are creating a production site you should load these assets sepa
469450

470451
#### Two approaches to writing your own frameworks
471452

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.
473454

474455
## Contributions and future development
475456

@@ -483,7 +464,7 @@ This library is mostly functional (I'm already using it in another large site, w
483464

484465
* 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.
485466

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.
487468

488469
* 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:
489470

src/demo/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$demo-app-primary: mat-palette($mat-blue);
55
$demo-app-accent: mat-palette($mat-amber, A200, A100, A400);
66
$demo-app-warn: mat-palette($mat-red);
7-
$demo-app-theme: mat-light-theme($demo-app-primary, $demo-app-accent, $demo-app-warn);
7+
$demo-app-theme: mat-light-theme($demo-app-primary, $demo-app-accent, $demo-app-warn);
88
@include angular-material-theme($demo-app-theme);
99

1010
$font-family: 'Roboto', 'Noto', 'Helvetica Neue', sans-serif;

0 commit comments

Comments
 (0)