Skip to content

Commit 434c2d5

Browse files
Merge branch 'development' into update-docs
2 parents 99d1630 + 9f15cf5 commit 434c2d5

File tree

18 files changed

+580
-20
lines changed

18 files changed

+580
-20
lines changed

dist/bootstrap-decorator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/schema-form.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.md

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ of the titleMap can be HTML.
332332
}
333333
```
334334

335+
The submit button has btn-primary as default. The button has btn-default as default.
336+
We can change this with ```style``` attribute:
337+
```javascript
338+
{
339+
type: "actions",
340+
items: [
341+
{ type: 'submit', style: 'btn-success', title: 'Ok' }
342+
{ type: 'button', style: 'btn-info', title: 'Cancel', onClick: "cancel()" }
343+
]
344+
}
345+
```
346+
335347
### button
336348

337349
*button* can have a ```onClick``` attribute that either, as in JSON Form, is a function *or* a
@@ -345,6 +357,15 @@ the ```sf-schema``` directive.
345357
[
346358
```
347359

360+
The submit button has btn-primary as default. The button has btn-default as default.
361+
We can change this with ```style``` attribute:
362+
```javascript
363+
[
364+
{ type: 'button', style: 'btn-warning', title: 'Ok', onClick: function(){ ... } }
365+
{ type: 'button', style: 'btn-danger', title: 'Cancel', onClick: "cancel()" }
366+
[
367+
```
368+
348369
### radios and radiobuttons
349370
Both type *radios* and *radiobuttons* work the same way, they take a titleMap
350371
and renders ordinary radio buttons or bootstrap 3 buttons inline. It's a
@@ -376,6 +397,37 @@ function FormCtrl($scope) {
376397
}
377398
```
378399

400+
With *radiobuttons*, both selected and unselected buttons have btn-primary as default.
401+
We can change this with ```style``` attribute:
402+
```javascript
403+
function FormCtrl($scope) {
404+
$scope.schema = {
405+
type: "object",
406+
properties: {
407+
choice: {
408+
type: "string",
409+
enum: ["one","two"]
410+
}
411+
}
412+
};
413+
414+
$scope.form = [
415+
{
416+
key: "choice",
417+
type: "radiobuttons",
418+
style: {
419+
selected: "btn-success",
420+
unselected: "btn-default"
421+
},
422+
titleMap: {
423+
one: "One",
424+
two: "More..."
425+
}
426+
}
427+
];
428+
}
429+
```
430+
379431
### help
380432
Help fields is not really a field, but instead let's you insert arbitrary HTML
381433
into a form, suitable for help texts with links etc.
@@ -470,9 +522,9 @@ schemas. Only a schema is supported by Schema Form, and not the list of schemas.
470522
The *form* definition has the option ```ìtems``` that should be a list
471523
of form objects.
472524

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.
525+
The rendered list of subforms each have a *"Remove"* button and at the bottom there
526+
is an *"Add"* button. The default *"Add"* button has class btn-default and text Add. Both
527+
could be changed using attribute ```add```, see example below.
476528

477529
If you like to have drag and drop reordering of arrays you also need
478530
[ui-sortable](https://github.com/angular-ui/ui-sortable) and its dependencies
@@ -566,6 +618,9 @@ function FormCtrl($scope) {
566618
{
567619
key: "subforms",
568620
add: "Add person",
621+
style: {
622+
add: "btn-success"
623+
},
569624
items: [
570625
"subforms[].nick",
571626
"subforms[].name",
@@ -585,8 +640,11 @@ By default the tabs are on the left side (follows the default in JSON Form),
585640
but with the option ```tabType``` you can change that to eiter *"top"* or *"right"*
586641
as well.
587642

588-
Every tab page has a *"Remove"* button, you can change the text on that with
589-
the ```remove``` option.
643+
Every tab page has a *"Remove"* button. The default *"Remove"* button has class btn-default
644+
and text Remove. Both could be changed using attribute ```remove```, see example below.
645+
646+
In this case we have an *"Add"* link, not an *"Add"* button. Therefore, the attribute ```add```
647+
only changes the text of the link. See example below.
590648

591649
Bootstrap 3 doesn't have side tabs so to get proper styling you need to add the
592650
dependency [bootstrap-vertical-tabs](https://github.com/dbtek/bootstrap-vertical-tabs).
@@ -630,7 +688,11 @@ function FormCtrl($scope) {
630688
tabType: "top",
631689
title: "value.nick || ('Tab '+$index)"
632690
key: "subforms",
633-
add: "Add person",
691+
remove: "Delete",
692+
style: {
693+
remove: "btn-danger"
694+
},
695+
add: "Add person",
634696
items: [
635697
"subforms[].nick",
636698
"subforms[].name",

examples/data/array.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
},
3838
{
3939
"key": "comments",
40+
"add": "New",
41+
"style": {
42+
"add": "btn-success"
43+
},
4044
"items": [
4145
"comments[].name",
4246
"comments[].email",
@@ -48,6 +52,7 @@
4852
},
4953
{
5054
"type": "submit",
55+
"style": "btn-info",
5156
"title": "OK"
5257
}
5358
]

examples/data/simple.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
},
3232
{
3333
"type": "submit",
34+
"style": "btn-info",
3435
"title": "OK"
3536
}
3637
]

examples/data/sink.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,23 @@
182182
},
183183
{
184184
"key": "radiobuttons",
185+
"style": {
186+
"selected": "btn-success",
187+
"unselected": "btn-default"
188+
},
185189
"type": "radiobuttons"
186190
},
187191
{
188192
"type": "actions",
189193
"items": [
190194
{
191195
"type": "submit",
196+
"style": "btn-info",
192197
"title": "Do It!"
193198
},
194199
{
195200
"type": "button",
201+
"style": "btn-danger",
196202
"title": "Noooooooooooo",
197203
"onClick": "sayNo()"
198204
}

examples/data/tabarray.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
{
3939
"key": "comments",
4040
"type": "tabarray",
41+
"add": "New",
42+
"remove": "Delete",
43+
"style": {
44+
"remove": "btn-danger"
45+
},
4146
"title": "value.name || 'Tab '+$index",
4247
"items": [
4348
"comments[].name",
@@ -50,6 +55,7 @@
5055
},
5156
{
5257
"type": "submit",
58+
"style": "btn-default",
5359
"title": "OK"
5460
}
5561
]

gulpfile.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ gulp.task('minify',function(){
6969
});
7070

7171

72-
gulp.task('default',['minify','bootstrap','bootstrap-datepicker']);
72+
gulp.task('non-minified-dist',function(){
73+
gulp.src([
74+
'./src/module.js',
75+
'./src/services/*.js',
76+
'./src/directives/*.js'
77+
])
78+
.pipe(concat('schema-form.js'))
79+
.pipe(gulp.dest('./dist/'));
80+
});
81+
82+
83+
gulp.task('default',['minify','bootstrap','bootstrap-datepicker','non-minified-dist']);
7384

7485

7586
gulp.task('watch', function() {

src/directives/decorators/bootstrap/actions.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="btn-group">
22
<input ng-repeat-start="item in form.items"
33
type="submit"
4-
class="btn btn-primary"
4+
class="btn {{ item.style || 'btn-primary' }}"
55
value="{{item.title}}"
66
ng-if="item.type === 'submit'">
7-
<button ng-repeat-end class="btn btn-default"
7+
<button ng-repeat-end class="btn {{ item.style || 'btn-default' }}"
88
type="button"
99
ng-if="item.type !== 'submit'"
1010
ng-click="buttonClick($event,item)">{{item.title}}</button>

src/directives/decorators/bootstrap/array.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h3 ng-show="form.title && form.notitle !== true">{{ form.title }}</h3>
1313
<div class="clearfix" style="padding: 15px;">
1414
<button ng-click="appendToArray()"
1515
type="button"
16-
class="btn btn-default pull-right">
16+
class="btn {{ form.style.add || 'btn-default' }} pull-right">
1717
<i class="glyphicon glyphicon-plus"></i>
1818
{{ form.add || 'Add'}}
1919
</button>

src/directives/decorators/bootstrap/checkboxes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="form-group" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}" ng-init="checkboxValues = {}">
1+
<div class="form-group" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}" ng-init="checkboxValues = listToCheckboxValues($$value$$)">
22
<label ng-show="showTitle()">{{form.title}}</label>
33
<div class="checkbox" ng-repeat="value in form.schema.items.enum" >
44
<label>

src/directives/decorators/bootstrap/radio-buttons.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="form-group" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}">
22
<label ng-show="showTitle()">{{form.title}}</label>
33
<div class="btn-group">
4-
<label class="btn btn-primary"
4+
<label class="btn {{ (value === $$value$$) ? form.style.selected || 'btn-primary' : form.style.unselected || 'btn-primary'; }}"
55
ng-class="{ active: value === $$value$$ }"
66
ng-repeat="(value,name) in form.titleMap">
77
<input type="radio"

src/directives/decorators/bootstrap/submit.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class="form-group">
22
<input type="submit"
3-
class="btn btn-primary"
3+
class="btn {{ form.style || 'btn-primary' }}"
44
value="{{form.title}}"
55
ng-if="form.type === 'submit'">
6-
<button class="btn btn-default"
6+
<button class="btn {{ form.style || 'btn-default' }}"
77
type="button"
88
ng-click="buttonClick($event,form)"
99
ng-if="form.type !== 'submit'">{{form.title}}</button>

src/directives/decorators/bootstrap/tabarray.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<div ng-class="{'col-xs-9': !form.tabsType || form.tabsType === 'left' || form.tabsType === 'right'}">
2323
<div class="tab-content">
24-
<div class="tab-pane claerfix"
24+
<div class="tab-pane clearfix"
2525
ng-repeat="item in modelArray track by $index"
2626
ng-show="selected.tab === $index"
2727
ng-class="{active: selected.tab === $index}">
@@ -30,7 +30,7 @@
3030

3131
<button ng-click="deleteFromArray($index)"
3232
type="button"
33-
class="btn btn-default pull-right">
33+
class="btn {{ form.style.remove || 'btn-default' }} pull-right">
3434
<i class="glyphicon glyphicon-trash"></i>
3535
{{ form.remove || 'Remove'}}
3636
</button>

src/services/Select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @description
77
* Utility method to access deep properties without
8-
* trhowing errors when things are not defined.
8+
* throwing errors when things are not defined.
99
* Can also set a value in a deep structure, creating objects when missing
1010
* ex.
1111
* var foo = Select('address.contact.name',obj)

src/services/decorators.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ angular.module('schemaForm').provider('schemaFormDecorators',['$compileProvider'
6565
return scope.form && scope.form.notitle !== true && scope.form.title;
6666
};
6767

68+
scope.listToCheckboxValues = function(list){
69+
var values = {};
70+
angular.forEach(list,function(v){
71+
values[v] = true;
72+
});
73+
return values;
74+
};
75+
6876
scope.checkboxValuesToList = function(values){
6977
var lst = [];
7078
angular.forEach(values,function(v,k){

src/services/schema-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
2525
if (schema.title) f.title = schema.title;
2626
if (schema.description) f.description = schema.description;
2727
if (options.required === true || schema.required === true) f.required = true;
28-
if (schema.default) f.default = schema.default;
28+
if (schema.default !== undefined) f.default = schema.default;
2929
if (schema.maxLength) f.maxlength = schema.maxLength;
3030
if (schema.minLength) f.minlength = schema.maxLength;
3131
if (schema.readOnly || schema.readonly) f.readonly = schema.readOnly || schema.readonly;

0 commit comments

Comments
 (0)