Skip to content

Commit cdc3d0a

Browse files
committed
Updated docs, deps and known limitations
1 parent 98b7ca7 commit cdc3d0a

File tree

3 files changed

+122
-19
lines changed

3 files changed

+122
-19
lines changed

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Schema Form uses convention over configuration, so it comes packaged with some s
2222

2323
JSON Form
2424
---------
25-
Schema Form is inspired by the nice [JSON Form](https://github.com/joshfire/jsonform) library and aims to be roughly compatible with it, especially its form definition. So what sets Schema Form apart from JSON Form?
25+
Schema Form is inspired by the nice [JSON Form](https://github.com/joshfire/jsonform) library and aims to be roughly compatible with it, especially its form definition. So what sets Schema Form apart from JSON Form?
2626

27-
1. Schema Form integrates deeply with AngularJS and uses AngularJS conventions to handle forms.
28-
2. Schema Form uses [tv4](https://github.com/geraintluff/tv4) for validation, making it compatible with version 4 of the JSON schema standard.
27+
1. Schema Form integrates deeply with AngularJS and uses AngularJS conventions to handle forms.
28+
2. Schema Form uses [tv4](https://github.com/geraintluff/tv4) for validation, making it compatible with version 4 of the JSON schema standard.
2929
3. By default, Schema Form generates Bootstrap 3-friendly HTML.
3030

3131

@@ -79,27 +79,41 @@ Installation
7979

8080
### Bower
8181

82-
It's simplest to install Schema Form using [Bower](http://bower.io/) since it will come packaged with all of its dependencies.
82+
It's simplest to install Schema Form using [Bower](http://bower.io/).
8383

8484
```bash
8585
bower install angular-schema-form
8686
```
8787

88+
This will install the latest release and basic dependencies. See
89+
[dependecies section below](#dependencies).
90+
8891
### Manual
8992

9093
You can also just download the contents of the `dist/` folder and add dependencies manually.
9194

9295
### Dependencies
9396

97+
Schema form has a lot of dependencies, most of which are optional. Therefor
98+
9499
Schema Form depends on:
95100

96-
1. [AngularJS](https://angularjs.org/) (duh!)
101+
1. [AngularJS](https://angularjs.org/) version 1.3.x is recomended. Version 1.2.x
102+
has some limitation. See [known limitations](docs/knownlimitations.md).
97103
2. [angular-sanitize](https://docs.angularjs.org/api/ngSanitize)
98-
3. [bootstrap 3](http://getbootstrap.com/)
99-
4. [tv4](https://github.com/geraintluff/tv4)
100-
5. If you want to use the date picker, you'll also need [jQuery](https://github.com/jquery/jquery) and [pickadate.js](http://amsul.ca/pickadate.js/)
101-
7. If you'd like to use drag-and-drop reordering of arrays, you'll also need [ui-sortable](https://github.com/angular-ui/ui-sortable) and its [jQueryUI](http://jqueryui.com/) dependencies. See the *ui-sortable* documentation for details about which parts of jQueryUI are needed. You can safely ignore these if you don't need reordering.
102-
8. Schema Form provides tabbed arrays through the form type `tabarray`. Tab arrays default to tabs on the left side. For these to work, you'll need to include the CSS from [bootstrap-vertical-tabs](https://github.com/dbtek/bootstrap-vertical-tabs). However, you won't need Bootstrap Vertical Tabs for horizontal tabs (the `tabType: "top"` option).
104+
3. [tv4](https://github.com/geraintluff/tv4)
105+
4. [objectpath](https://github.com/mike-marcacci/objectpath)
106+
5. [bootstrap 3](http://getbootstrap.com/)
107+
108+
If you install via bower you get all of the above except bootstrap since we
109+
don't want to push a certain version or flavor on you. Also make
110+
sure you got the angular version you actually want.
111+
112+
#### Additional dependecies
113+
114+
1. If you want to use the date picker, you'll also need [jQuery](https://github.com/jquery/jquery) and [pickadate.js](http://amsul.ca/pickadate.js/)
115+
2. If you'd like to use drag-and-drop reordering of arrays, you'll also need [ui-sortable](https://github.com/angular-ui/ui-sortable) and its [jQueryUI](http://jqueryui.com/) dependencies. See the *ui-sortable* documentation for details about which parts of jQueryUI are needed. You can safely ignore these if you don't need reordering.
116+
3. Schema Form provides tabbed arrays through the form type `tabarray`. Tab arrays default to tabs on the left side. For these to work, you'll need to include the CSS from [bootstrap-vertical-tabs](https://github.com/dbtek/bootstrap-vertical-tabs). However, you won't need Bootstrap Vertical Tabs for horizontal tabs (the `tabType: "top"` option).
103117

104118
The minified files include templates - no need to load additional HTML files.
105119

docs/index.md

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Documentation
22
=============
33

4+
1. [Basic Usage](#basic-usage)
45
1. [Form types](#form-types)
56
1. [Default form types](#default-form-types)
67
1. [Form definitions](#form-definitions)
@@ -22,6 +23,61 @@ Documentation
2223
1. [tabarray](#tabarray)
2324
1. [Post process function](#post-process-function)
2425

26+
Basic Usage
27+
-----------
28+
29+
First, expose your schema, form, and model to the $scope.
30+
31+
```javascript
32+
function FormController($scope) {
33+
$scope.schema = {
34+
type: "object",
35+
properties: {
36+
name: { type: "string", minLength: 2, title: "Name", description: "Name or alias" },
37+
title: {
38+
type: "string",
39+
enum: ['dr','jr','sir','mrs','mr','NaN','dj']
40+
}
41+
}
42+
};
43+
44+
$scope.form = [
45+
"*",
46+
{
47+
type: "submit",
48+
title: "Save"
49+
}
50+
];
51+
52+
$scope.model = {};
53+
}
54+
```
55+
56+
Then load them into Schema Form using the `sfSchema`, `sfForm`, and `sfModel` directives.
57+
58+
```html
59+
<div ng-controller="FormController">
60+
<form sf-schema="schema" sf-form="form" sf-model="model"></form>
61+
</div>
62+
```
63+
64+
The `sfSchema` directive doesn't need to be on a form tag, in fact it can be quite useful
65+
to set it on a div or some such inside the form instead. Especially if you like to prefix or suffix the
66+
form with buttons or fields that are hard coded.
67+
68+
Example with custom submit buttons:
69+
```html
70+
<div ng-controller="FormController">
71+
<form>
72+
<p>bla bla bla</p>
73+
<div sf-schema="schema" sf-form="form" sf-model="model"></div>
74+
<input type="submit" value="Submit">
75+
<button type="button" ng-click="goBack()">Cancel</button>
76+
</form>
77+
</div>
78+
```
79+
80+
2581
Form types
2682
----------
2783
Schema Form currently supports the following form field types out of the box:
@@ -332,7 +388,7 @@ of the titleMap can be HTML.
332388
}
333389
```
334390

335-
The submit button has btn-primary as default. The button has btn-default as default.
391+
The submit button has btn-primary as default. The button has btn-default as default.
336392
We can change this with ```style``` attribute:
337393
```javascript
338394
{
@@ -342,7 +398,7 @@ We can change this with ```style``` attribute:
342398
{ type: 'button', style: 'btn-info', title: 'Cancel', onClick: "cancel()" }
343399
]
344400
}
345-
```
401+
```
346402

347403
### button
348404

@@ -357,14 +413,14 @@ the ```sf-schema``` directive.
357413
[
358414
```
359415

360-
The submit button has btn-primary as default. The button has btn-default as default.
416+
The submit button has btn-primary as default. The button has btn-default as default.
361417
We can change this with ```style``` attribute:
362418
```javascript
363419
[
364420
{ type: 'button', style: 'btn-warning', title: 'Ok', onClick: function(){ ... } }
365421
{ type: 'button', style: 'btn-danger', title: 'Cancel', onClick: "cancel()" }
366422
[
367-
```
423+
```
368424

369425
### radios and radiobuttons
370426
Both type *radios* and *radiobuttons* work the same way, they take a titleMap
@@ -397,7 +453,7 @@ function FormCtrl($scope) {
397453
}
398454
```
399455

400-
With *radiobuttons*, both selected and unselected buttons have btn-primary as default.
456+
With *radiobuttons*, both selected and unselected buttons have btn-primary as default.
401457
We can change this with ```style``` attribute:
402458
```javascript
403459
function FormCtrl($scope) {
@@ -523,7 +579,7 @@ The *form* definition has the option ```ìtems``` that should be a list
523579
of form objects.
524580

525581
The rendered list of subforms each have a *"Remove"* button and at the bottom there
526-
is an *"Add"* button. The default *"Add"* button has class btn-default and text Add. Both
582+
is an *"Add"* button. The default *"Add"* button has class btn-default and text Add. Both
527583
could be changed using attribute ```add```, see example below.
528584

529585
If you like to have drag and drop reordering of arrays you also need
@@ -640,10 +696,10 @@ By default the tabs are on the left side (follows the default in JSON Form),
640696
but with the option ```tabType``` you can change that to eiter *"top"* or *"right"*
641697
as well.
642698

643-
Every tab page has a *"Remove"* button. The default *"Remove"* button has class btn-default
644-
and text Remove. Both could be changed using attribute ```remove```, see example below.
699+
Every tab page has a *"Remove"* button. The default *"Remove"* button has class btn-default
700+
and text Remove. Both could be changed using attribute ```remove```, see example below.
645701

646-
In this case we have an *"Add"* link, not an *"Add"* button. Therefore, the attribute ```add```
702+
In this case we have an *"Add"* link, not an *"Add"* button. Therefore, the attribute ```add```
647703
only changes the text of the link. See example below.
648704

649705
Bootstrap 3 doesn't have side tabs so to get proper styling you need to add the

docs/knownlimitations.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Known Limitations
2+
=================
3+
4+
### Angular Version
5+
Schema Form works with AngularJS version 1.2.x or above, but version 1.3.x is recomended.
6+
7+
This is because a bug in AngularJS 1.2 [#8039](https://github.com/angular/angular.js/issues/8039),
8+
which means that the ```ng-model``` directive has problem with values that uses a bracket notation instead of dot notation.
9+
```html
10+
<!-- dot notation -->
11+
<input ng-model="foo.bar.baz">
12+
13+
<!-- bracket notation -->
14+
<input ng-model="foo['bar']['baz']">
15+
```
16+
17+
So what does that mean for you as a user of Schema Form? Basically it boils down to that if you use AngularJS 1.2.x
18+
Schema Form uses dot notation, which means your property names in the JSON schema *must not contain any hyphens or other
19+
characters dot notation cannot handle*.
20+
21+
Example schema that only works in 1.3
22+
```javascript
23+
{
24+
"type": "object",
25+
"properties": {
26+
"key-with-hyphen": { "type": "string" },
27+
}
28+
}
29+
```
30+
31+
The "complex keys" example schema illustrates this as well.
32+
For more background check out issue [#41](https://github.com/Textalk/angular-schema-form/issues/41) and the PR that fixed
33+
it, [PR 43](https://github.com/Textalk/angular-schema-form/pull/43). Thanks to @mike-marcacci for his excellent work!

0 commit comments

Comments
 (0)