File tree 4 files changed +44
-4
lines changed
src/Kris/LaravelFormBuilder/Fields
4 files changed +44
-4
lines changed Original file line number Diff line number Diff line change 7
7
convertWarningsToExceptions =" true"
8
8
processIsolation =" false"
9
9
stopOnFailure =" false"
10
- syntaxCheck = " false " >
10
+ >
11
11
<testsuites >
12
12
<testsuite name =" Package Test Suite" >
13
13
<directory suffix =" .php" >./tests/</directory >
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ protected function setupValue()
145
145
if ($ this instanceof EntityType) {
146
146
$ attributeName = $ this ->name ;
147
147
} else {
148
- $ attributeName = $ this ->getOption ('property ' , $ this ->name );
148
+ $ attributeName = $ this ->getOption ('value_property ' , $ this ->name );
149
149
}
150
150
151
151
$ this ->setValue ($ this ->getModelValueAttribute ($ this ->parent ->getModel (), $ attributeName ));
Original file line number Diff line number Diff line change @@ -139,6 +139,25 @@ public function it_creates_collection_with_child_form_with_correct_model()
139
139
}
140
140
}
141
141
142
+ /** @test */
143
+ public function it_creates_collection_with_child_form_with_correct_model_properties ()
144
+ {
145
+ $ items = new \Illuminate \Support \Collection ([
146
+ (new DummyEloquentModel2 ())->forceFill (['id ' => 1 , 'foo ' => 'bar ' ]),
147
+ (new DummyEloquentModel2 ())->forceFill (['id ' => 2 , 'foo ' => 'baz ' ]),
148
+ ]);
149
+
150
+ $ model = (new DummyEloquentModel ())->forceFill (['id ' => 11 ]);
151
+ $ model ->setRelation ('items ' , $ items );
152
+
153
+ $ form = $ this ->formBuilder ->create ('\LaravelFormBuilderCollectionTypeTest\Forms\NamespacedDummyFormCollectionForm ' , [
154
+ 'model ' => $ model ,
155
+ ]);
156
+
157
+ $ collectionValue = $ form ->getField ('items ' )->getOption ('data ' );
158
+ $ this ->assertEquals ($ items , $ collectionValue );
159
+ }
160
+
142
161
/**
143
162
* @test
144
163
*/
@@ -227,4 +246,25 @@ class DummyEloquentModel2 extends Model {
227
246
class NamespacedDummyForm extends Form
228
247
{
229
248
}
249
+
250
+ class NamespacedDummyFormCollectionChildForm extends Form
251
+ {
252
+ function buildForm ()
253
+ {
254
+ $ this ->add ('foo ' , 'text ' );
255
+ }
256
+ }
257
+
258
+ class NamespacedDummyFormCollectionForm extends Form
259
+ {
260
+ function buildForm ()
261
+ {
262
+ $ this ->add ('items ' , 'collection ' , [
263
+ 'type ' => 'form ' ,
264
+ 'options ' => [
265
+ 'class ' => NamespacedDummyFormCollectionChildForm::class,
266
+ ],
267
+ ]);
268
+ }
269
+ }
230
270
}
Original file line number Diff line number Diff line change @@ -468,7 +468,7 @@ public function it_can_take_and_replace_existing_fields()
468
468
$ this ->plainForm ->only ('remember ' , 'name ' );
469
469
470
470
$ this ->assertEquals (2 , count ($ this ->plainForm ->getFields ()));
471
-
471
+
472
472
$ this ->assertTrue ($ this ->plainForm ->has ('remember ' ));
473
473
$ this ->assertTrue ($ this ->plainForm ->has ('name ' ));
474
474
$ this ->assertFalse ($ this ->plainForm ->has ('description ' ));
@@ -788,7 +788,7 @@ public function it_can_use_model_property_to_set_value()
788
788
]);
789
789
790
790
$ form ->add ('alias_accessor ' , 'choice ' , [
791
- 'property ' => 'accessor ' ,
791
+ 'value_property ' => 'accessor ' ,
792
792
]);
793
793
794
794
$ this ->assertEquals ($ form ->alias_accessor ->getValue (), $ this ->model ->accessor );
You can’t perform that action at this time.
0 commit comments