@@ -18,6 +18,8 @@ Documentation
18
18
1 . [ radios and radiobuttons] ( #radios-and-radiobuttons )
19
19
1 . [ help] ( #help )
20
20
1 . [ tabs] ( #tabs )
21
+ 1 . [ array] ( #array )
22
+ 1 . [ tabarray] ( #tabarray )
21
23
1 . [ Post process function] ( #post-process-function )
22
24
23
25
Form types
@@ -42,6 +44,8 @@ Schema Form currently supports the following form field types out of the box:
42
44
| radiobuttons | radio buttons with bootstrap buttons |
43
45
| help | insert arbitrary html |
44
46
| tab | tabs with content |
47
+ | array | a list you can add, remove and reorder |
48
+ | tabarray | a tabbed version of array |
45
49
46
50
More field types can be added, for instance a "datepicker" type can be added by
47
51
including the [ datepicker addon] ( datepicker.md )
@@ -62,6 +66,8 @@ a property.
62
66
| "type": "object" | fieldset |
63
67
| "type": "string" and a "enum" | select |
64
68
| "type": "array" and a "enum" in array type | checkboxes |
69
+ | "type": "array" | array |
70
+
65
71
66
72
67
73
Form definitions
@@ -455,6 +461,187 @@ function FormCtrl($scope) {
455
461
}
456
462
```
457
463
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
+
458
645
459
646
460
647
0 commit comments