From 79f6d2e50eb175adb5d84ee393492be7f3dc1477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Fri, 17 May 2019 10:04:16 +0200 Subject: [PATCH] Ensure multiselects work with dot-notation names Closes #115 --- .../views/forms/groups/checkboxes.blade.php | 2 +- .../views/forms/groups/multiselect.blade.php | 2 +- .../Feature/FormViewTests/CheckboxesTest.php | 22 ++++++++++++++++++ .../Feature/FormViewTests/MultiselectTest.php | 23 +++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/resources/views/forms/groups/checkboxes.blade.php b/resources/views/forms/groups/checkboxes.blade.php index a13308bc..b89bb2ae 100644 --- a/resources/views/forms/groups/checkboxes.blade.php +++ b/resources/views/forms/groups/checkboxes.blade.php @@ -7,7 +7,7 @@ 'errorsId' => $errorsId = $groupId . ($errorsSuffix ?? 'Errors'), 'labelAttributes' => $legendAttributes ?? [], ]) - + @include('kontour::forms.partials.checkableOptions') @include('kontour::forms.partials.errors') \ No newline at end of file diff --git a/resources/views/forms/groups/multiselect.blade.php b/resources/views/forms/groups/multiselect.blade.php index ab40331d..e302f43f 100644 --- a/resources/views/forms/groups/multiselect.blade.php +++ b/resources/views/forms/groups/multiselect.blade.php @@ -2,7 +2,7 @@ data-selected-options="{{ implode(' ', $selected = collect(($errors->any() ? old($name) : null) ?? $selected ?? $model[$name] ?? [])->map(function($item) { return strval($item instanceof Illuminate\Database\Eloquent\Model ? $item->getKey() : $item); })->all()) }}" @include('kontour::forms.partials.groupAttributes') > - + @include('kontour::forms.label', [ 'controlId' => $controlId = $controlId ?? (($idPrefix ?? '') . $name), ]) diff --git a/tests/Feature/FormViewTests/CheckboxesTest.php b/tests/Feature/FormViewTests/CheckboxesTest.php index ff02d658..65ef3731 100644 --- a/tests/Feature/FormViewTests/CheckboxesTest.php +++ b/tests/Feature/FormViewTests/CheckboxesTest.php @@ -19,6 +19,17 @@ public function test_checkboxes_has_array_name() $this->assertRegExp('//', $output); } + public function test_checkboxes_has_array_name_from_dot_notation() + { + $output = View::make('kontour::forms.checkboxes', [ + 'name' => 'test.name.in.dot.notation', + 'options' => ['a' => 'A', 'b' => 'B'], + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('//', $output); + } + public function test_checkboxes_has_hidden_presence_input() { $output = View::make('kontour::forms.checkboxes', [ @@ -30,6 +41,17 @@ public function test_checkboxes_has_hidden_presence_input() $this->assertRegExp('/[\S\s]*/', $output); } + public function test_checkboxes_has_hidden_presence_input_from_dot_notation() + { + $output = View::make('kontour::forms.checkboxes', [ + 'name' => 'test.name.in.dot.notation', + 'options' => ['a' => 'A', 'b' => 'B'], + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('/[\S\s]*/', $output); + } + public function test_fieldset_can_have_custom_control_id() { $output = View::make('kontour::forms.checkboxes', [ diff --git a/tests/Feature/FormViewTests/MultiselectTest.php b/tests/Feature/FormViewTests/MultiselectTest.php index 30553b0d..a5865958 100644 --- a/tests/Feature/FormViewTests/MultiselectTest.php +++ b/tests/Feature/FormViewTests/MultiselectTest.php @@ -19,6 +19,18 @@ public function test_multiselect_has_array_name() $this->assertRegExp('//', $output); } + public function test_multiselect_has_array_name_from_dot_notation() + { + $output = View::make('kontour::forms.multiselect', [ + 'name' => 'test.name.in.dot.notation', + 'options' => ['a' => 'A', 'b' => 'B'], + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('//', $output); + } + + public function test_multiselect_has_hidden_presence_input() { $output = View::make('kontour::forms.multiselect', [ @@ -30,6 +42,17 @@ public function test_multiselect_has_hidden_presence_input() $this->assertRegExp('/[\S\s]*/', $output); } + public function test_multiselect_has_hidden_presence_input_from_dot_notation() + { + $output = View::make('kontour::forms.multiselect', [ + 'name' => 'test.name.in.dot.notation', + 'options' => ['a' => 'A', 'b' => 'B'], + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('/[\S\s]*/', $output); + } + public function test_select_is_referenced_by_label() { $output = View::make('kontour::forms.multiselect', [