@@ -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 )
21231 . [ Post process function] ( #post-process-function )
2224
2325Form 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
4650More field types can be added, for instance a "datepicker" type can be added by
4751including 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
6773Form 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