Skip to content

Commit f12689e

Browse files
committed
rework mechanism of nesting
1 parent fa2020c commit f12689e

15 files changed

+347
-324
lines changed

app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</div>
4242
<div class="col-md-4">
4343
<h4 class="no-margin">Simple form</h4>
44-
<formus-form config="form.config" model="form.data" fieldset="form.fieldset"></formus-form>
44+
<formus-form config="form.config" model="form.data" fieldset="form.fieldset" errors="form.errors"></formus-form>
4545
</div>
4646
<div class="col-md-4">
4747
<h4 class="no-margin">JSON configuration</h4>

app/js/app.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,42 @@ var app = angular.module('app', [
55
app.constant('FORMS_CONFIG', formsConfiguration);
66

77
/** Set source of forms configuration */
8-
app.config(['FormusContainerProvider', 'FORMS_CONFIG', function (FormusContainerProvider, FORMS_CONFIG) {
8+
app.config(['FormusContainerProvider', 'FORMS_CONFIG', function(FormusContainerProvider, FORMS_CONFIG) {
99
FormusContainerProvider.setContainer(FORMS_CONFIG);
1010
}]);
1111

12-
app.controller('MainCtrl', function ($scope, FormusContainer, FORMS_CONFIG) {
12+
app.controller('MainCtrl', function($scope, FormusContainer, FORMS_CONFIG) {
1313
var form = $scope.form = FormusContainer.get('firstForm');
14-
$scope.src= FORMS_CONFIG.firstForm;
15-
form.config.buttons[0].handler = function (){
16-
form.fieldset.fields[0].label = 'Test';
14+
$scope.src = FORMS_CONFIG.firstForm;
15+
form.config.buttons[0].handler = function() {
16+
form.fieldset.fields[0].label = 'Test';
17+
};
18+
form.config.buttons[1].handler = function() {
19+
form.errors = {
20+
"type": {
21+
"category": {
22+
"name": ["Test error"]
23+
}
24+
}
25+
};
26+
};
27+
form.config.buttons[2].handler = function() {
28+
form.data.type.category.name = 'Test';
1729
};
1830
});
1931

20-
app.config(['FormusValidatorProvider', function (FormusValidatorProvider) {
21-
FormusValidatorProvider.set('match', function (value, config, arg) {
22-
var re;
23-
if (typeof(arg) === 'string') {
24-
re = new RegExp(arg);
25-
}
26-
if (arg instanceof RegExp) {
27-
re = arg;
28-
}
29-
if (!re.test(value)) {
30-
return config.label + ' is invalid';
31-
}
32-
return null;
33-
});
34-
}]);
32+
app.config(['FormusValidatorProvider', function(FormusValidatorProvider) {
33+
FormusValidatorProvider.set('match', function(value, config, arg) {
34+
var re;
35+
if (typeof(arg) === 'string') {
36+
re = new RegExp(arg);
37+
}
38+
if (arg instanceof RegExp) {
39+
re = arg;
40+
}
41+
if (!re.test(value)) {
42+
return config.label + ' is invalid';
43+
}
44+
return null;
45+
});
46+
}]);

app/js/forms.js

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,99 @@ var formsConfiguration = {
22
firstForm: {
33
title: 'Info',
44
fieldset: {
5-
fields: [{
6-
name: 'nested.test',
75
fields: [{
8-
name: 'name',
9-
label: 'Name',
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',
1029
input: 'textbox',
30+
default: 'mysite.com'
31+
}, {
32+
name: 'address',
33+
label: 'Address',
34+
input: 'textarea',
35+
rows: 2,
1136
validators: {
1237
required: true
1338
}
1439
}, {
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: 'usa',
49-
title: 'USA'
50-
}],
51-
validators: {
52-
required: true
53-
}
54-
}, {
55-
name: 'timezone',
56-
label: 'Timezone',
57-
input: 'select',
58-
validators: {
59-
required: true
60-
},
61-
items: [{
62-
value: 1,
63-
title: 'ACT'
64-
}, {
65-
value: 2,
66-
title: 'North'
67-
}, {
68-
value: 3,
69-
title: 'NSW'
70-
}, {
71-
value: 4,
72-
title: 'Queensland'
73-
}, {
74-
value: 5,
75-
title: 'South'
76-
}, {
77-
value: 6,
78-
title: 'Victoria'
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+
}
7957
}, {
80-
value: 7,
81-
title: 'West'
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+
}]
8286
}]
83-
}]
8487
},
8588
config: {
8689
buttons: [{
8790
class: 'btn btn-danger',
8891
title: 'Cancel'
92+
}, {
93+
class: 'btn btn-warning',
94+
title: 'Set Erros'
95+
}, {
96+
class: 'btn btn-success',
97+
title: 'Set Field'
8998
}],
9099
submit: {
91100
class: 'btn btn-primary'

0 commit comments

Comments
 (0)