diff --git a/examples/bootstrap-example.html b/examples/bootstrap-example.html index 5bef56a..c7908b2 100644 --- a/examples/bootstrap-example.html +++ b/examples/bootstrap-example.html @@ -214,9 +214,9 @@

Schema

- + + + @@ -254,6 +254,9 @@

Schema

{ name: "TitleMap Examples", data: 'data/titlemaps.json' }, { name: "Kitchen Sink", data: 'data/sink.json' }, { name: "Hack: Conditional required", data: 'data/conditional-required.json' }, + { name: "Tab Array: Add Disabled", data: 'data/tabarray-add-disabled.json' }, + { name: "Tab Array: Remove Disabled", data: 'data/tabarray-remove-disabled.json' }, + { name: "Tab Array: Sortable (Drag and Drop)", data: 'data/tabarray-sortable.json' } ]; $scope.navbarMode = 'default'; diff --git a/examples/data/tabarray-add-disabled.json b/examples/data/tabarray-add-disabled.json new file mode 100644 index 0000000..b604e22 --- /dev/null +++ b/examples/data/tabarray-add-disabled.json @@ -0,0 +1,44 @@ +{ + "schema": { + "type": "object", + "title": "Tab Array: Add Disabled", + "properties": { + "addDisabledTabArray": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "nick": { "type": "string" } + } + } + } + } + }, + "form": [ + { + "type": "section", + "htmlCss": "row", + "items": [ + { + "type": "help", + "helpvalue": "

Tab array with add link hidden

" + }, + { + "key": "addDisabledTabArray", + "type": "tabarray", + "add": null, + "title": "My name is: {{ value.name }}", + "sortOptions": { + "disabled": true + }, + "items" : [ + {"key": "addDisabledTabArray[].name", "htmlClass": "nameField"}, + {"key": "addDisabledTabArray[].nick", "htmlClass": "nickField"} + ] + } + ] + } + ], + "model": {} +} diff --git a/examples/data/tabarray-remove-disabled.json b/examples/data/tabarray-remove-disabled.json new file mode 100644 index 0000000..74e818e --- /dev/null +++ b/examples/data/tabarray-remove-disabled.json @@ -0,0 +1,44 @@ +{ + "schema": { + "type": "object", + "title": "Tab Array: Remove Disabled", + "properties": { + "removeDisabledTabArray": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "nick": { "type": "string" } + } + } + } + } + }, + "form": [ + { + "type": "section", + "htmlCss": "row", + "items": [ + { + "type": "help", + "helpvalue": "

Tab array with remove button hidden

" + }, + { + "key": "removeDisabledTabArray", + "type": "tabarray", + "remove": null, + "title": "My name is: {{ value.name }}", + "sortOptions": { + "disabled": true + }, + "items" : [ + {"key": "removeDisabledTabArray[].name", "htmlClass": "nameField"}, + {"key": "removeDisabledTabArray[].nick", "htmlClass": "nickField"} + ] + } + ] + } + ], + "model": {} +} diff --git a/examples/data/tabarray-sortable.json b/examples/data/tabarray-sortable.json new file mode 100644 index 0000000..3eda316 --- /dev/null +++ b/examples/data/tabarray-sortable.json @@ -0,0 +1,40 @@ +{ + "schema": { + "type": "object", + "title": "Tab Array: Sortable (Drag and Drop)", + "properties": { + "sortableTabArray": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "nick": { "type": "string" } + } + } + } + } + }, + "form": [ + { + "type": "section", + "htmlCss": "row", + "items": [ + { + "type": "help", + "helpvalue": "

Drag and drop sortable tab array

" + }, + { + "key": "sortableTabArray", + "type": "tabarray", + "title": "My name is: {{ value.name }}", + "items" : [ + {"key": "sortableTabArray[].name", "htmlClass": "nameField"}, + {"key": "sortableTabArray[].nick", "htmlClass": "nickField"} + ] + } + ] + } + ], + "model": {} +} diff --git a/gulp/tasks/protractor.js b/gulp/tasks/protractor.js index 9a3bb18..9c410e8 100644 --- a/gulp/tasks/protractor.js +++ b/gulp/tasks/protractor.js @@ -27,7 +27,7 @@ gulp.task('protractor', ['webdriver-update'], function(cb) { }).on('end', cb); }); -['validation-messages', 'custom-validation'].forEach(function(name) { +['validation-messages', 'custom-validation', 'tabarray'].forEach(function(name) { gulp.task('protractor:' + name, ['webdriver-update'], function(cb) { gulp.src(['test/protractor/specs/' + name + '.js']).pipe(protractor.protractor({ configFile: 'test/protractor/conf.js', diff --git a/src/bootstrap-decorator.js b/src/bootstrap-decorator.js index 8c20653..1deb784 100644 --- a/src/bootstrap-decorator.js +++ b/src/bootstrap-decorator.js @@ -27,13 +27,24 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) { }); } }; + + // Set tabArray sortOptions.items default. + var tabArray = function(args) { + if(args.form.hasOwnProperty('sortOptions')) { + if(!args.form.sortOptions.hasOwnProperty('items')) { + args.form.sortOptions['items'] = 'li:not(:last-child)'; + } + } else { + args.form['sortOptions'] = {items: 'li:not(:last-child)'}; + } + } var defaults = [sfField, ngModel, ngModelOptions, condition]; decoratorsProvider.defineDecorator('bootstrapDecorator', { textarea: {template: base + 'textarea.html', builder: defaults}, fieldset: {template: base + 'fieldset.html', builder: [sfField, simpleTransclusion, condition]}, array: {template: base + 'array.html', builder: [sfField, ngModelOptions, ngModel, array, condition]}, - tabarray: {template: base + 'tabarray.html', builder: [sfField, ngModelOptions, ngModel, array, condition]}, + tabarray: {template: base + 'tabarray.html', builder: [sfField, ngModelOptions, ngModel, array, condition, tabArray]}, tabs: {template: base + 'tabs.html', builder: [sfField, ngModelOptions, tabs, condition]}, section: {template: base + 'section.html', builder: [sfField, simpleTransclusion, condition]}, conditional: {template: base + 'section.html', builder: [sfField, simpleTransclusion, condition]}, diff --git a/src/tabarray.html b/src/tabarray.html index e7a5b8a..1e8de1b 100644 --- a/src/tabarray.html +++ b/src/tabarray.html @@ -6,15 +6,16 @@ class="clearfix schema-form-tabarray schema-form-tabarray-{{form.tabType || 'left'}} {{form.htmlClass}}">
- +
@@ -35,7 +36,7 @@
-