Skip to content

Commit edec694

Browse files
committed
Merge branch 'release/v0.6.0'
2 parents 266775e + 49edc5b commit edec694

24 files changed

+1102
-189
lines changed

CHANGELOG

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
v0.6.0
2+
------
3+
* array and tabarray support, with help from @zackbloom (thanks!).
4+
Schema type array now translates to a list of objects, adding, removing
5+
and reordering supported. Form type "tabarray" does the same but renders
6+
it as tabs instead (configurable to left, right or top)
7+
18
v0.5.0
29
------
310
* Travis and Coveralls integration
411
* Support for HTML in descriptons and some titles, (checkbox(es), radios).
512
* ngSanitize is now a dependency.
6-
* Enum order is now maintained in selects (thanks @adamschwartz)
13+
* Enum order is now maintained in selects (thanks @adamschwartz)
714

815
v0.4.0
916
------

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Generate forms from a JSON schema, with AngularJS!
1414
What is it?
1515
----------
1616

17-
Schema Form is a set of AngularJS directives (and a service..) that can create a form directly from a json schema
17+
Schema Form is a set of AngularJS directives (and a couple of services..) that can create a form directly from a json schema
1818
definition and also validate against that schema. The defaults may be fine for a lot cases, but you can also
1919
customize it, changing order and type of fields.
2020

@@ -77,11 +77,23 @@ manually)
7777

7878
It depends on [AngularJS](https://angularjs.org/) (duh!),
7979
[angular-sanitize](https://docs.angularjs.org/api/ngSanitize),
80+
[bootstrap 3](http://getbootstrap.com/),
8081
[tv4](https://github.com/geraintluff/tv4), and
8182
if you like to use the date picker you also need jQuery and
8283
[pickadate.js](http://amsul.ca/pickadate.js/). Also if you use the ```help```
8384
type to inject HTML you'll want to use ngSanitize as well.
8485

86+
If you like to have drag and drop reordering of arrays you also need
87+
[ui-sortable](https://github.com/angular-ui/ui-sortable) and its dependencies
88+
[jQueryUI](http://jqueryui.com/), see *ui-sortable* documentation for details of
89+
what parts of jQueryUI that is needed. You can safely ignore these if you don't
90+
need the reordering.
91+
92+
Tabbed arrays, form type ```tabarray```, defaults to tabs on the left side. For
93+
these to work you also need to include the css from
94+
[bootstrap-vertical-tabs](https://github.com/dbtek/bootstrap-vertical-tabs).
95+
It is not needed for tabs on top, the ```tabType: "top"``` option.
96+
8597
The minified files also includes all templates so they are all you need.
8698

8799
Addons

bower.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
"dist/bootstrap-decorator.min.js",
66
"dist/bootstrap-datepicker.min.js"
77
],
8-
"version": "0.5.0",
8+
"version": "0.6.0",
99
"authors": [
1010
"Textalk",
1111
"David Jensen <[email protected]>"
1212
],
1313
"moduleType": [
1414
"globals"
1515
],
16+
"keywords": ["angular","angularjs","form","json","json-schema","schema"],
1617
"license": "MIT",
1718
"ignore": [
1819
"**/.*",
@@ -25,7 +26,8 @@
2526
"angular": "~1.2.18",
2627
"tv4": "~1.0.15",
2728
"pickadate": "~3.5.2",
28-
"angular-sanitize": "~1.2.18"
29+
"angular-sanitize": "~1.2.18",
30+
"bootstrap-vertical-tabs": "~1.1.0"
2931
},
3032
"devDependencies": {
3133
"angular-ui-ace": "bower"

dist/bootstrap-decorator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/schema-form.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.md

+187
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Documentation
1818
1. [radios and radiobuttons](#radios-and-radiobuttons)
1919
1. [help](#help)
2020
1. [tabs](#tabs)
21+
1. [array](#array)
22+
1. [tabarray](#tabarray)
2123
1. [Post process function](#post-process-function)
2224

2325
Form types
@@ -42,6 +44,8 @@ Schema Form currently supports the following form field types out of the box:
4244
| radiobuttons | radio buttons with bootstrap buttons |
4345
| help | insert arbitrary html |
4446
| tab | tabs with content |
47+
| array | a list you can add, remove and reorder |
48+
| tabarray | a tabbed version of array |
4549

4650
More field types can be added, for instance a "datepicker" type can be added by
4751
including the [datepicker addon](datepicker.md)
@@ -62,6 +66,8 @@ a property.
6266
| "type": "object" | fieldset |
6367
| "type": "string" and a "enum" | select |
6468
| "type": "array" and a "enum" in array type | checkboxes |
69+
| "type": "array" | array |
70+
6571

6672

6773
Form definitions
@@ -455,6 +461,187 @@ function FormCtrl($scope) {
455461
}
456462
```
457463

464+
### array
465+
The ```array``` form type is the default for the schema type ```array```.
466+
The schema for an array has the property ```"items"``` which in the JSON Schema
467+
specification can be either another schema (i.e. and object), or a list of
468+
schemas. Only a schema is supported by Schema Form, and not the list of schemas.
469+
470+
The *form* definition has the option ```ìtems``` that should be a list
471+
of form objects.
472+
473+
The rendered list of subforms each have a remove button and at the bottom there
474+
is an add button. The text of the add button can be changed by the option
475+
```add``` , see example below.
476+
477+
If you like to have drag and drop reordering of arrays you also need
478+
[ui-sortable](https://github.com/angular-ui/ui-sortable) and its dependencies
479+
[jQueryUI](http://jqueryui.com/), see *ui-sortable* documentation for details of
480+
what parts of jQueryUI that is needed. You can safely ignore these if you don't
481+
need the reordering.
482+
483+
In the form definition you can refer to properties of an array item by the empty
484+
bracket notation. In the ```key``` simply end the name of the array with ```[]```
485+
486+
Given the schema:
487+
```json
488+
{
489+
"type": "object",
490+
"properties": {
491+
"subforms": {
492+
"type": "array",
493+
"items": {
494+
"type": "object",
495+
"properties": {
496+
"name": { "type": "string" },
497+
"nick": { "type": "string" },
498+
"emails": {
499+
"type": "array",
500+
"items": {
501+
"type": "string"
502+
}
503+
}
504+
}
505+
}
506+
}
507+
}
508+
}
509+
```
510+
Then ```subforms[].name``` refers to the property name of any subform item,
511+
```subforms[].emails[]``` refers to the subform of emails. See example below for
512+
usage.
513+
514+
515+
Single list of inputs example:
516+
```javascript
517+
function FormCtrl($scope) {
518+
$scope.schema = {
519+
type: "object",
520+
properties: {
521+
names: {
522+
type: "array",
523+
items: {
524+
title: "Name",
525+
type: "string"
526+
}
527+
}
528+
}
529+
};
530+
531+
$scope.form = ['*'];
532+
}
533+
```
534+
535+
536+
Example with sub form, note that you can get rid of the form field the object wrapping the
537+
subform fields gives you per default by using the ```items``` option in the
538+
form definition.
539+
540+
```javascript
541+
function FormCtrl($scope) {
542+
$scope.schema = {
543+
"type": "object",
544+
"properties": {
545+
"subforms": {
546+
"type": "array",
547+
"items": {
548+
"type": "object",
549+
"properties": {
550+
"name": { "type": "string" },
551+
"nick": { "type": "string" },
552+
"emails": {
553+
"type": "array",
554+
"items": {
555+
"type": "string"
556+
}
557+
}
558+
}
559+
}
560+
}
561+
}
562+
};
563+
564+
565+
$scope.form = [
566+
{
567+
key: "subforms",
568+
add: "Add person",
569+
items: [
570+
"subforms[].nick",
571+
"subforms[].name",
572+
"subforms[].emails",
573+
]
574+
}
575+
];
576+
}
577+
```
578+
579+
580+
### tabarray
581+
The ```tabarray``` form type behaves the same way and has the same options as
582+
```array``` but instead of rendering a list it renders a tab per item in list.
583+
584+
By default the tabs are on the left side (follows the default in JSON Form),
585+
but with the option ```tabType``` you can change that to eiter *"top"* or *"right"*
586+
as well.
587+
588+
Every tab page has a *"Remove"* button, you can change the text on that with
589+
the ```remove``` option.
590+
591+
Bootstrap 3 doesn't have side tabs so to get proper styling you need to add the
592+
dependency [bootstrap-vertical-tabs](https://github.com/dbtek/bootstrap-vertical-tabs).
593+
It is not needed for tabs on top.
594+
595+
The ```title``` option is a bit special in ```tabarray```, it defines the title
596+
of the tab and is considered a angular expression. The expression is evaluated
597+
with two extra variables in context: **value** and **$index**, where **value**
598+
is the value in the array (i.e. that tab) and **$index** the index.
599+
600+
Example with tabs on the top:
601+
602+
```javascript
603+
function FormCtrl($scope) {
604+
$scope.schema = {
605+
"type": "object",
606+
"properties": {
607+
"subforms": {
608+
"type": "array",
609+
"items": {
610+
"type": "object",
611+
"properties": {
612+
"name": { "type": "string" },
613+
"nick": { "type": "string" },
614+
"emails": {
615+
"type": "array",
616+
"items": {
617+
"type": "string"
618+
}
619+
}
620+
}
621+
}
622+
}
623+
}
624+
};
625+
626+
627+
$scope.form = [
628+
{
629+
type: "tabarray",
630+
tabType: "top",
631+
title: "value.nick || ('Tab '+$index)"
632+
key: "subforms",
633+
add: "Add person",
634+
items: [
635+
"subforms[].nick",
636+
"subforms[].name",
637+
"subforms[].emails",
638+
]
639+
}
640+
];
641+
}
642+
```
643+
644+
458645

459646

460647

0 commit comments

Comments
 (0)