Skip to content

Commit

Permalink
Merge branch 'master' into feature/login-autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-epineer authored Jun 28, 2019
2 parents 0e5fc4c + 4c41e6e commit 3f0c96d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 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
2 changes: 1 addition & 1 deletion resources/views/forms/partials/inputAttributes.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name="{{ preg_replace('/\.([^\.]*)/', '[$1]', $name) }}"
@include('kontour::forms.partials.nameAttribute')
id="{{ $controlId }}"
@if($errors->hasAny($errorsKeys ?? $name))
aria-invalid="true"
Expand Down
1 change: 1 addition & 0 deletions resources/views/forms/partials/nameAttribute.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name="{{ preg_replace('/\.([^.[]+)/', '[$1]', $name) }}"
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 3f0c96d

Please sign in to comment.