Skip to content

Commit

Permalink
Ensure multiselects work with dot-notation names
Browse files Browse the repository at this point in the history
Closes #115
  • Loading branch information
bjuppa committed May 17, 2019
1 parent 045204c commit 79f6d2e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/views/forms/groups/checkboxes.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'errorsId' => $errorsId = $groupId . ($errorsSuffix ?? 'Errors'),
'labelAttributes' => $legendAttributes ?? [],
])
<input type="hidden" name="{{ $name }}" value="">
<input type="hidden" @include('kontour::forms.partials.nameAttribute') value="">
@include('kontour::forms.partials.checkableOptions')
@include('kontour::forms.partials.errors')
</fieldset>
2 changes: 1 addition & 1 deletion resources/views/forms/groups/multiselect.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
>
<input type="hidden" name="{{ $name }}" value="">
<input type="hidden" @include('kontour::forms.partials.nameAttribute') value="">
@include('kontour::forms.label', [
'controlId' => $controlId = $controlId ?? (($idPrefix ?? '') . $name),
])
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/FormViewTests/CheckboxesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public function test_checkboxes_has_array_name()
$this->assertRegExp('/<input[\S\s]*name="test\[]"[\S\s]*>/', $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('/<input[\S\s]*name="test\[name]\[in]\[dot]\[notation]\[]"[\S\s]*>/', $output);
}

public function test_checkboxes_has_hidden_presence_input()
{
$output = View::make('kontour::forms.checkboxes', [
Expand All @@ -30,6 +41,17 @@ public function test_checkboxes_has_hidden_presence_input()
$this->assertRegExp('/<input type="hidden" name="test" value="">[\S\s]*<input[\S\s]*type="checkbox"[\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('/<input type="hidden" name="test\[name]\[in]\[dot]\[notation]" value="">[\S\s]*<input[\S\s]*type="checkbox"[\S\s]*>/', $output);
}

public function test_fieldset_can_have_custom_control_id()
{
$output = View::make('kontour::forms.checkboxes', [
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/FormViewTests/MultiselectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public function test_multiselect_has_array_name()
$this->assertRegExp('/<select[\S\s]*name="test\[]"[\S\s]*>/', $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('/<select[\S\s]*name="test\[name]\[in]\[dot]\[notation]\[]"[\S\s]*>/', $output);
}


public function test_multiselect_has_hidden_presence_input()
{
$output = View::make('kontour::forms.multiselect', [
Expand All @@ -30,6 +42,17 @@ public function test_multiselect_has_hidden_presence_input()
$this->assertRegExp('/<input type="hidden" name="test" value="">[\S\s]*<select[\S\s]*multiple[\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('/<input type="hidden" name="test\[name]\[in]\[dot]\[notation]" value="">[\S\s]*<select[\S\s]*multiple[\S\s]*>/', $output);
}

public function test_select_is_referenced_by_label()
{
$output = View::make('kontour::forms.multiselect', [
Expand Down

0 comments on commit 79f6d2e

Please sign in to comment.