Skip to content

Commit 6cc56cb

Browse files
committed
tabs
1 parent 6c8fb47 commit 6cc56cb

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/bootstrap-decorator.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* TODO: starting form in tabarray, and arrays.
3+
*/
14
angular.module('schemaForm').config(['schemaFormDecoratorsProvider', 'sfBuilderProvider', 'sfPathProvider',
25
function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
36
var base = 'decorators/bootstrap/';
@@ -32,13 +35,32 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
3235
items.appendChild(childFrag);
3336
}
3437
};
38+
39+
var tabs = function(args) {
40+
if (args.form.tabs && args.form.tabs.length > 0) {
41+
var tabContent = args.fieldFrag.querySelector('.tab-content');
42+
43+
args.form.tabs.forEach(function(tab, index) {
44+
var div = document.createElement('div');
45+
div.className = 'tab-pane';
46+
div.setAttribute('ng-disabled', 'form.readonly');
47+
div.setAttribute('ng-show', 'selected.tab === ' + index);
48+
div.setAttribute('ng-class', '{active: selected.tab === ' + index + '}');
49+
50+
var childFrag = args.build(tab.items, args.path + '.tabs[' + index + '].items', args.state);
51+
div.appendChild(childFrag);
52+
tabContent.appendChild(div);
53+
});
54+
}
55+
};
56+
3557
var defaults = [sfField, ngModel, ngModelOptions];
3658
decoratorsProvider.defineDecorator('bootstrapDecorator', {
3759
textarea: {template: base + 'textarea.html', builder: defaults},
3860
fieldset: {template: base + 'fieldset.html', builder: [sfField, simpleTransclusion]},
3961
array: {template: base + 'array.html', builder: [sfField, ngModelOptions, ngModel, array]},
4062
tabarray: {template: base + 'tabarray.html', builder: [sfField, ngModelOptions, ngModel, array]},
41-
tabs: {template: base + 'tabs.html', replace: false},
63+
tabs: {template: base + 'tabs.html', builder: [sfField, ngModelOptions, ngModel, tabs]},
4264
section: {template: base + 'section.html', builder: [sfField, simpleTransclusion]},
4365
conditional: {template: base + 'section.html', builder: [sfField, simpleTransclusion]},
4466
actions: {template: base + 'actions.html', builder: defaults},

src/tabs.html

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
</ul>
1010

1111
<div class="tab-content {{form.fieldHtmlClass}}">
12-
<div class="tab-pane"
13-
ng-disabled="form.readonly"
14-
ng-repeat="tab in form.tabs"
15-
ng-show="selected.tab === $index"
16-
ng-class="{active: selected.tab === $index}">
17-
<bootstrap-decorator ng-repeat="item in tab.items" form="item">
18-
</bootstrap-decorator>
19-
</div>
12+
</div>
2013
</div>
2114
</div>

0 commit comments

Comments
 (0)