Skip to content

Commit 751ee01

Browse files
committed
add button input
1 parent 6f32313 commit 751ee01

File tree

10 files changed

+138
-88
lines changed

10 files changed

+138
-88
lines changed

app/js/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ app.config(['FormusContainerProvider', 'FORMS_CONFIG', function(FormusContainerP
1212
app.controller('MainCtrl', function($scope, FormusContainer, FORMS_CONFIG) {
1313
var form = $scope.form = FormusContainer.get('firstForm');
1414
$scope.src = FORMS_CONFIG.firstForm;
15+
form.fieldset.fields[7].fields[2].handler = function() {
16+
var config = angular.copy(form.data.newField);
17+
form.fieldset.fields.push(config);
18+
};
1519
form.config.buttons[0].handler = function() {
1620
form.fieldset.fields[0].label = 'Test';
1721
};
@@ -44,4 +48,3 @@ app.config(['FormusValidatorProvider', function(FormusValidatorProvider) {
4448
return null;
4549
});
4650
}]);
47-

app/js/forms.js

Lines changed: 106 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,124 @@ var formsConfiguration = {
22
firstForm: {
33
title: 'Info',
44
fieldset: {
5+
fields: [{
6+
name: 'type.category',
57
fields: [{
6-
name: 'type.category',
7-
fields: [{
8-
name: 'name',
9-
label: 'Name',
10-
input: 'textbox',
11-
validators: {
12-
required: true
13-
}
14-
}, {
15-
name: 'id',
16-
label: ' ID',
17-
input: 'textbox',
18-
readonly: true,
19-
default: 1,
20-
addon: '#'
21-
}]
22-
}, {
23-
name: 'checkValue',
24-
input: 'checkbox',
25-
label: 'Check Box'
26-
}, {
27-
name: 'website',
28-
label: 'Website',
8+
name: 'name',
9+
label: 'Name',
2910
input: 'textbox',
30-
default: 'mysite.com'
31-
}, {
32-
name: 'address',
33-
label: 'Address',
34-
input: 'textarea',
35-
rows: 2,
3611
validators: {
3712
required: true
3813
}
3914
}, {
40-
name: 'currency',
41-
label: 'Currency',
15+
name: 'id',
16+
label: ' ID',
17+
input: 'textbox',
18+
readonly: true,
19+
default: 1,
20+
addon: '#'
21+
}]
22+
}, {
23+
name: 'checkValue',
24+
input: 'checkbox',
25+
label: 'Check Box'
26+
}, {
27+
name: 'website',
28+
label: 'Website',
29+
input: 'textbox',
30+
default: 'mysite.com'
31+
}, {
32+
name: 'address',
33+
label: 'Address',
34+
input: 'textarea',
35+
rows: 2,
36+
validators: {
37+
required: true
38+
}
39+
}, {
40+
name: 'currency',
41+
label: 'Currency',
42+
input: 'select',
43+
empty: 'Select ...',
44+
items: [{
45+
value: 'aud',
46+
title: 'AUD'
47+
}, {
48+
value: 'eur',
49+
title: 'EUR'
50+
}, {
51+
value: 'usa',
52+
title: 'USA'
53+
}],
54+
validators: {
55+
required: true
56+
}
57+
}, {
58+
name: 'timezone',
59+
label: 'Timezone',
60+
input: 'select',
61+
validators: {
62+
required: true
63+
},
64+
items: [{
65+
value: 1,
66+
title: 'ACT'
67+
}, {
68+
value: 2,
69+
title: 'North'
70+
}, {
71+
value: 3,
72+
title: 'NSW'
73+
}, {
74+
value: 4,
75+
title: 'Queensland'
76+
}, {
77+
value: 5,
78+
title: 'South'
79+
}, {
80+
value: 6,
81+
title: 'Victoria'
82+
}, {
83+
value: 7,
84+
title: 'West'
85+
}]
86+
}, {
87+
name: 'radio',
88+
label: 'Radio',
89+
input: 'radio',
90+
items: [{
91+
value: true,
92+
title: 'Yes'
93+
}, {
94+
value: false,
95+
title: 'No'
96+
}],
97+
default: true
98+
}, {
99+
label: 'New field',
100+
class: 'table-bordered padding-10',
101+
name: 'newField',
102+
fields: [{
103+
label: 'Input type:',
42104
input: 'select',
43-
empty: 'Select ...',
105+
name: 'input',
44106
items: [{
45-
value: 'aud',
46-
title: 'AUD'
47-
}, {
48-
value: 'eur',
49-
title: 'EUR'
107+
value: 'textbox',
108+
title: 'Textbox'
50109
}, {
51-
value: 'usa',
52-
title: 'USA'
110+
value: 'select',
111+
title: 'Select'
53112
}],
54-
validators: {
55-
required: true
56-
}
113+
default: 'textbox'
57114
}, {
58-
name: 'timezone',
59-
label: 'Timezone',
60-
input: 'select',
61-
validators: {
62-
required: true
63-
},
64-
items: [{
65-
value: 1,
66-
title: 'ACT'
67-
}, {
68-
value: 2,
69-
title: 'North'
70-
}, {
71-
value: 3,
72-
title: 'NSW'
73-
}, {
74-
value: 4,
75-
title: 'Queensland'
76-
}, {
77-
value: 5,
78-
title: 'South'
79-
}, {
80-
value: 6,
81-
title: 'Victoria'
82-
}, {
83-
value: 7,
84-
title: 'West'
85-
}]
86-
},{
87-
name: 'radio',
88-
label: 'Radio',
89-
input: 'radio',
90-
items: [{value:true, title: 'Yes'}, {value:false, title: 'No'}],
91-
default: true
115+
name: 'name',
116+
label: 'Name',
117+
input: 'textbox'
118+
}, {
119+
title: 'Add',
120+
input: 'button'
92121
}]
122+
}]
93123
},
94124
config: {
95125
buttons: [{

app/js/formus.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ formus.provider('FormusConfig', function($logProvider) {
4747
},
4848
radio: function() {
4949
return {
50-
inline:true
50+
inline: true
5151
}
5252
},
5353
radio: function() {
@@ -60,6 +60,12 @@ formus.provider('FormusConfig', function($logProvider) {
6060
'class': 'bordered'
6161
};
6262
},
63+
button: function() {
64+
return {
65+
class: 'btn btn-primary',
66+
handler: function() {}
67+
};
68+
},
6369
file: function() {
6470
return {
6571
showLink: true
@@ -77,7 +83,7 @@ formus.provider('FormusConfig', function($logProvider) {
7783
if (configs[name]) {
7884
return configs[name]();
7985
}
80-
// $log.info('Don\'t find config for input "' + name + '"');
86+
// $log.info('Don\'t find config for input "' + name + '"');
8187
return getDefault();
8288
};
8389
return {
@@ -602,7 +608,7 @@ formus.provider('FormusTemplates', function() {
602608
textarea: 'formus/inputs/textarea.html',
603609
textbox: 'formus/inputs/textbox.html',
604610
fieldset: 'formus/inputs/fieldset.html',
605-
message: 'formus/inputs/message.html',
611+
button: 'formus/inputs/button.html',
606612
label: 'formus/inputs/label.html',
607613
};
608614

app/js/templates.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/styles/main.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
.no-margin {
88
margin: 0;
99
}
10+
.padding-10 {
11+
padding: 10px;
12+
}

src/config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ formus.provider('FormusConfig', function($logProvider) {
4141
},
4242
radio: function() {
4343
return {
44-
inline:true
44+
inline: true
4545
}
4646
},
4747
radio: function() {
@@ -54,6 +54,12 @@ formus.provider('FormusConfig', function($logProvider) {
5454
'class': 'bordered'
5555
};
5656
},
57+
button: function() {
58+
return {
59+
class: 'btn btn-primary',
60+
handler: function() {}
61+
};
62+
},
5763
file: function() {
5864
return {
5965
showLink: true
@@ -71,7 +77,7 @@ formus.provider('FormusConfig', function($logProvider) {
7177
if (configs[name]) {
7278
return configs[name]();
7379
}
74-
// $log.info('Don\'t find config for input "' + name + '"');
80+
// $log.info('Don\'t find config for input "' + name + '"');
7581
return getDefault();
7682
};
7783
return {

src/templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ formus.provider('FormusTemplates', function() {
1414
textarea: 'formus/inputs/textarea.html',
1515
textbox: 'formus/inputs/textbox.html',
1616
fieldset: 'formus/inputs/fieldset.html',
17-
message: 'formus/inputs/message.html',
17+
button: 'formus/inputs/button.html',
1818
label: 'formus/inputs/label.html',
1919
};
2020

src/views/inputs/button.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<button type="button" class="{{config.class}}" ng-bind="config.title" ng-click="config.handler()">
2+
</button>

src/views/inputs/fieldset.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<div class="row">
2-
</div>
1+
<div class="{{config.class}}">
32
<formus-wrapper ng-repeat="field in config.fields" class="{{config.wrapClass}}">
43
<formus-field config="field"></formus-field>
54
</formus-wrapper>

src/views/inputs/wrapper.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="form-group margin-bottom-5" ng-class="{'has-error': !input.isValid}">
2-
<label for="{{input.config.name}}" ng-show="input.config.showLabel" ng-bind="input.config.label"></label>
2+
<label for="{{input.config.name}}" ng-if="input.config.showLabel" ng-bind="input.config.label"></label>
33
<div ng-transclude>
44
</div>
55
<span class="help-block" ng-if="input.config.showErrors" ng-repeat="e in input.errors" ng-bind="e"></span>

0 commit comments

Comments
 (0)