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
+74-43Lines changed: 74 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,12 @@ A [JSON Schema](http://json-schema.org) Form builder for Angular 4 and 5, simila
9
9
*[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
10
10
*[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/))
11
11
12
-
Note: This is currently a personal proof-of-concept project, and is NOT affiliated with any of the organizations listed above. (Though they are all awesome, and totally worth checking out.)
12
+
Note: This is currently a personal proof-of-concept project, and is not affiliated with any of the organizations listed above. (Though they are all awesome, and totally worth checking out.)
13
+
14
+
## Breaking change in version 0.7.0-alpha.1 and above
15
+
16
+
You must now import both JsonSchemaFormModule and a framework module. (Don't worry, it's easy.)
17
+
For full details, see 'To install from NPM and use in your own project', below.
13
18
14
19
## Check out the live demo and play with the examples
Note that you have to import both the main JsonSchemaFormModule and a separate framework module (in this example, MaterialDesignFrameworkModule).
84
+
85
+
The framework module is listed in your imports section twice, once by itself (to load the framework's components) and again in the JsonSchemaFormModule.forRoot() function (to load the framework's service and tell Angular JSON Schema Form to use it).
86
+
87
+
Four framework modules are currently included:
88
+
89
+
* MaterialDesignFrameworkModule — Material Design
90
+
* Bootstrap3FrameworkModule — Bootstrap 3
91
+
* Bootstrap4FrameworkModule — Bootstrap 4
92
+
* NoFrameworkModule — plain HTML (for testing)
93
+
94
+
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.
95
+
73
96
#### Seed Application Examples
74
97
75
98
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:
@@ -80,9 +103,9 @@ For complete examples of how to install and configure Angular JSON Schema Form t
80
103
81
104
#### Additional notes for Angular CLI
82
105
83
-
Make sure you are running the latest version of Angular CLI.
106
+
Make sure you are running a recent version of Angular CLI.
84
107
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.
108
+
Very old 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.
86
109
87
110
#### Additional notes for SystemJS
88
111
@@ -95,6 +118,8 @@ Add these lines to the 'map' section of systemjs.config.js:
95
118
'lodash':'npm:lodash/lodash.min.js'
96
119
```
97
120
121
+
(Note: These instructions have not been tested recently. If you use SystemJS and have problems, please post a bug report on GitHub.)
122
+
98
123
## Using Angular JSON Schema Form
99
124
100
125
### Basic use
@@ -103,38 +128,22 @@ For basic use, after loading JsonSchemaFormModule as described above, to display
103
128
104
129
```html
105
130
<json-schema-form
106
-
framework="bootstrap-3"
107
131
loadExternalAssets="true"
108
132
[schema]="yourJsonSchema"
109
133
(onSubmit)="yourOnSubmitFn($event)">
110
134
</json-schema-form>
111
135
```
112
136
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
-
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.
116
-
117
-
Note: If you prefer brackets around all your attributes, the following is functionally equivalent:
118
-
119
-
```html
120
-
<json-schema-form
121
-
[framework]="'bootstrap-3'"
122
-
[loadExternalAssets]="true"
123
-
[schema]="yourJsonSchema"
124
-
(onSubmit)="yourOnSubmitFn($event)">
125
-
</json-schema-form>
126
-
```
127
-
128
-
If you use this syntax, make sure to include the nested quotes (`"'` and `'"`) around the framework name.
137
+
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 `src/demo/assets/example-schemas` folder, as described above.
129
138
139
+
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.
130
140
131
141
### Data-only mode
132
142
133
143
Angular JSON Schema Form can also create a form entirely from a JSON object—with no schema—like so:
134
144
135
145
```html
136
146
<json-schema-form
137
-
framework="bootstrap-4"
138
147
loadExternalAssets="true"
139
148
[(ngModel)]="exampleJsonObject">
140
149
</json-schema-form>
@@ -166,13 +175,14 @@ Also, notice that the 'ngModel' input supports Angular's 2-way data binding, jus
166
175
167
176
For more control over your form, you may provide these additional inputs:
168
177
169
-
*`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)
170
-
*`data` - object to populate the form with default or previously submitted values
171
-
*`options` - object to set any global options for the form
172
-
*`widgets` to add custom widgets
173
-
*`framework` - string or object to set which framework to use
174
-
set to 'bootstrap-3', 'bootstrap-4', 'material-design', or
175
-
'no-framework' (the default), or pass in your own custom framework object
178
+
*`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)
179
+
*`data` object to populate the form with default or previously submitted values
180
+
*`options` object to set any global options for the form
181
+
*`widgets` object to add custom widgets
182
+
*`language` string to set the error message language (currently supports 'en' and 'fr')
183
+
*`framework` string or object to set which framework to use
184
+
185
+
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'.
176
186
177
187
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.
178
188
@@ -185,6 +195,7 @@ Here is an example:
185
195
[(data)]="yourData"
186
196
[options]="yourFormOptions"
187
197
[widgets]="yourCustomWidgets"
198
+
language="fr"
188
199
framework="material-design"
189
200
loadExternalAssets="true"
190
201
(onChanges)="yourOnChangesFn($event)"
@@ -194,18 +205,40 @@ Here is an example:
194
205
</json-schema-form>
195
206
```
196
207
208
+
Note: If you prefer brackets around all your attributes, the following is functionally equivalent:
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.)
228
+
197
229
#### Single-input mode
198
230
199
231
You may also combine all your inputs into one compound object and include it as a `form` input, like so:
200
232
201
233
```javascript
202
234
let yourCompoundInputObject = {
203
-
schema: { ... }, //required
235
+
schema: { ... }, //REQUIRED
204
236
layout: [ ... ], // optional
205
237
data: { ... }, // optional
206
238
options: { ... }, // optional
207
239
widgets: { ... }, // optional
208
-
framework: { ... } // optional
240
+
language:'...' , // optional
241
+
framework:'...'// (or { ... }) optional
209
242
}
210
243
```
211
244
@@ -216,9 +249,9 @@ let yourCompoundInputObject = {
216
249
</json-schema-form>
217
250
```
218
251
219
-
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.
252
+
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.
220
253
221
-
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.
254
+
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.
222
255
223
256
#### Compatibility modes
224
257
@@ -254,9 +287,7 @@ JSON Form (jQuery) compatibility:
254
287
</json-schema-form>
255
288
```
256
289
257
-
Note: 2-way data binding will work with any dedicated data input,
258
-
including 'data', 'model', 'ngModel', or 'formData'.
259
-
However, 2-way binding will _not_ work with the combined 'form' input.
290
+
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.
0 commit comments