File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
Tests/FormlyMapper/FormlyField Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,15 @@ public function getFormlyFieldConfiguration()
35
35
*/
36
36
protected function buildConfiguration ()
37
37
{
38
+ $ this ->formlyFieldConfiguration = [];
38
39
$ this ->formlyFieldConfiguration ['key ' ] = $ this ->fieldConfiguration ['name ' ];
39
40
$ this ->formlyFieldConfiguration ['type ' ] = 'input ' ;
40
41
42
+ if (isset ($ this ->fieldConfiguration ['options ' ]['data ' ])) {
43
+ $ this ->formlyFieldConfiguration ['defaultValue ' ] = $ this ->fieldConfiguration ['options ' ]['data ' ];
44
+ unset($ this ->fieldConfiguration ['options ' ]['data ' ]);
45
+ }
46
+
41
47
if (isset ($ this ->fieldConfiguration ['options ' ])) {
42
48
$ templateOptions = $ this ->fieldConfiguration ['options ' ];
43
49
$ templateOptions ['label ' ] = ucfirst ($ this ->fieldConfiguration ['name ' ]);
Original file line number Diff line number Diff line change @@ -24,13 +24,18 @@ protected function buildFieldTypeConfiguration()
24
24
25
25
if (isset ($ validation ['Symfony\Component\Validator\Constraints\Range ' ])) {
26
26
$ constraint = $ validation ['Symfony\Component\Validator\Constraints\Range ' ];
27
- $ this ->formlyFieldConfiguration ['templateOptions ' ]['min ' ] = isset ($ constraint ['min ' ]) ? $ constraint ['min ' ] : '' ;
27
+
28
+ if (isset ($ constraint ['min ' ])) {
29
+ $ this ->formlyFieldConfiguration ['templateOptions ' ]['min ' ] = $ constraint ['min ' ];
30
+ }
28
31
29
32
if (isset ($ constraint ['minMessage ' ])) {
30
33
$ this ->formlyFieldConfiguration ['validation ' ]['messages ' ]['min ' ] = $ constraint ['minMessage ' ];
31
34
}
32
35
33
- $ this ->formlyFieldConfiguration ['templateOptions ' ]['max ' ] = isset ($ constraint ['max ' ]) ? $ constraint ['max ' ] : '' ;
36
+ if (isset ($ constraint ['max ' ])) {
37
+ $ this ->formlyFieldConfiguration ['templateOptions ' ]['max ' ] = $ constraint ['max ' ];
38
+ }
34
39
35
40
if (isset ($ constraint ['maxMessage ' ])) {
36
41
$ this ->formlyFieldConfiguration ['validation ' ]['messages ' ]['max ' ] = $ constraint ['maxMessage ' ];
Original file line number Diff line number Diff line change @@ -19,12 +19,14 @@ public function testIsAddingNumberFields()
19
19
'options ' => [
20
20
'required ' => true ,
21
21
'label ' => 'Width ' ,
22
+ 'data ' => 255 ,
22
23
],
23
24
];
24
25
25
26
$ expected = [
26
27
'key ' => 'width ' ,
27
28
'type ' => 'input ' ,
29
+ 'defaultValue ' => 255 ,
28
30
'templateOptions ' => [
29
31
'type ' => 'number ' ,
30
32
'label ' => 'Width ' ,
@@ -46,10 +48,11 @@ public function testIsRangeConstraint()
46
48
'options ' => [
47
49
'required ' => true ,
48
50
'label ' => 'Age ' ,
51
+ 'data ' => 18 ,
49
52
],
50
53
'validation ' => [
51
54
'Symfony\Component\Validator\Constraints\Range ' => [
52
- 'min ' => 5 ,
55
+ 'min ' => 18 ,
53
56
'max ' => 100 ,
54
57
'minMessage ' => 'Min length minimum value should be at last {{ limit }} ' ,
55
58
'maxMessage ' => 'Max length maximum value should be at maximum {{ limit }} ' ,
@@ -60,12 +63,13 @@ public function testIsRangeConstraint()
60
63
$ expected = [
61
64
'key ' => 'age ' ,
62
65
'type ' => 'input ' ,
66
+ 'defaultValue ' => 18 ,
63
67
'templateOptions ' => [
64
68
'type ' => 'number ' ,
65
69
'label ' => 'Age ' ,
66
70
'required ' => true ,
67
- 'min ' => ' 5 ' ,
68
- 'max ' => ' 100 ' ,
71
+ 'min ' => 18 ,
72
+ 'max ' => 100 ,
69
73
],
70
74
'validation ' => [
71
75
'messages ' => [
@@ -89,6 +93,7 @@ public function testIsRegexConstraint()
89
93
'options ' => [
90
94
'required ' => true ,
91
95
'label ' => 'Age ' ,
96
+ 'data ' => 18 ,
92
97
],
93
98
'validation ' => [
94
99
'Symfony\Component\Validator\Constraints\Regex ' => [
@@ -101,6 +106,7 @@ public function testIsRegexConstraint()
101
106
$ expected = [
102
107
'key ' => 'age ' ,
103
108
'type ' => 'input ' ,
109
+ 'defaultValue ' => 18 ,
104
110
'templateOptions ' => [
105
111
'type ' => 'number ' ,
106
112
'label ' => 'Age ' ,
You can’t perform that action at this time.
0 commit comments