Skip to content

Commit d1dcff1

Browse files
authored
Merge pull request #5840 from Laravel-Backpack/fix-error-highlight
fix form error highlight
2 parents 9ef8a8e + 30f00a4 commit d1dcff1

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

src/resources/views/crud/components/dataform/form.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
>
1111
{!! csrf_field() !!}
1212

13-
<input type="hidden" name="_form_id" value="{{ $id }}">
1413
@if($method !== 'post')
1514
@method($method)
1615
@endif

src/resources/views/crud/create.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
@endsection
2929

3030
@section('content')
31-
3231
<div class="row" bp-section="crud-operation-create">
3332
<div class="{{ $crud->getCreateContentClass() }}">
3433
{{-- Default box --}}
3534

36-
@include('crud::inc.grouped_errors', ['id' => $id ?? null])
35+
@include('crud::inc.grouped_errors', ['id' => $id ?? 'crudForm'])
3736

3837
<form method="post"
3938
action="{{ url($crud->route) }}"
39+
id="{{ $id ?? 'crudForm' }}"
4040
@if ($crud->hasUploadFields('create'))
4141
enctype="multipart/form-data"
4242
@endif
4343
>
4444
{!! csrf_field() !!}
4545
{{-- load the view from the application if it exists, otherwise load the one in the package --}}
4646
@if(view()->exists('vendor.backpack.crud.form_content'))
47-
@include('vendor.backpack.crud.form_content', [ 'fields' => $crud->fields(), 'action' => 'create', 'id' => $id ?? null])
47+
@include('vendor.backpack.crud.form_content', [ 'fields' => $crud->fields(), 'action' => 'create', 'id' => $id ?? 'crudForm'])
4848
@else
49-
@include('crud::form_content', [ 'fields' => $crud->fields(), 'action' => 'create', 'id' => $id ?? null])
49+
@include('crud::form_content', [ 'fields' => $crud->fields(), 'action' => 'create', 'id' => $id ?? 'crudForm'])
5050
@endif
5151
{{-- This makes sure that all field assets are loaded. --}}
5252
<div class="d-none" id="parentLoadedAssets">{{ json_encode(Basset::loaded()) }}</div>

src/resources/views/crud/edit.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
<div class="{{ $crud->getEditContentClass() }}">
2929
{{-- Default box --}}
3030

31-
@include('crud::inc.grouped_errors', ['id' => $id])
31+
@include('crud::inc.grouped_errors', ['id' => $id ?? 'crudForm'])
32+
33+
{{-- This makes sure that all field assets are loaded. --}}
3234

3335
<form method="post"
3436
action="{{ url($crud->route.'/'.$entry->getKey()) }}"
37+
id="{{ $id ?? 'crudForm' }}"
3538
@if ($crud->hasUploadFields('update', $entry->getKey()))
3639
enctype="multipart/form-data"
3740
@endif
@@ -43,9 +46,9 @@
4346

4447
{{-- load the view from the application if it exists, otherwise load the one in the package --}}
4548
@if(view()->exists('vendor.backpack.crud.form_content'))
46-
@include('vendor.backpack.crud.form_content', ['fields' => $crud->fields(), 'action' => 'edit', 'id' => $id ?? null])
49+
@include('vendor.backpack.crud.form_content', ['fields' => $crud->fields(), 'action' => 'edit', 'id' => $id ?? 'crudForm'])
4750
@else
48-
@include('crud::form_content', ['fields' => $crud->fields(), 'action' => 'edit', 'id' => $id ?? null])
51+
@include('crud::form_content', ['fields' => $crud->fields(), 'action' => 'edit', 'id' => $id ?? 'crudForm'])
4952
@endif
5053
{{-- This makes sure that all field assets are loaded. --}}
5154
<div class="d-none" id="parentLoadedAssets">{{ json_encode(Basset::loaded()) }}</div>

src/resources/views/crud/form_content.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<input type="hidden" name="_http_referrer" value={{ session('referrer_url_override') ?? old('_http_referrer') ?? \URL::previous() ?? url($crud->route) }}>
2+
<input type="hidden" name="_form_id" value="{{ $id ?? 'crudForm' }}">
23

34
{{-- See if we're using tabs --}}
45
@if ($crud->tabsEnabled() && count($crud->getTabs()))

src/resources/views/crud/inc/grouped_errors.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{{-- Show the errors, if any --}}
22
@if ($crud->groupedErrorsEnabled() && session()->get('errors'))
33
@php
4-
$submittedFormId = old('_form_id') ?? null;
5-
$currentFormId = $id ?? null;
4+
$submittedFormId = old('_form_id') ?? 'crudForm';
5+
$currentFormId = $id ?? 'crudForm';
66
@endphp
77
@if (!$submittedFormId || $submittedFormId === $currentFormId)
8-
<div class="alert alert-danger">
9-
<ul class="list-unstyled">
8+
<div class="alert alert-danger text-danger">
9+
<ul class="list-unstyled mb-0">
1010
@foreach(session()->get('errors')->getBags() as $bag => $errorMessages)
1111
@foreach($errorMessages->getMessages() as $errorMessageForInput)
1212
@foreach($errorMessageForInput as $message)

0 commit comments

Comments
 (0)