Skip to content

Commit 1f0bba2

Browse files
committed
Fix errors not showing on field edit page
Fixes CMS-2009
1 parent 63205b6 commit 1f0bba2

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

resources/templates/settings/fields/_edit.twig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
instructions: "What this field will be called in the control panel."|t('app'),
1313
id: 'name',
1414
name: 'name',
15-
value: field.name,
15+
value: old('name', field.name),
1616
required: true,
1717
autofocus: true,
18-
errors: field.errors.get('name'),
18+
errors: errors.get('name'),
1919
data: {'error-key': 'name'},
2020
disabled: readOnly,
2121
}) }}
@@ -29,9 +29,9 @@
2929
autocorrect: false,
3030
autocapitalize: false,
3131
maxlength: 64,
32-
value: field.handle,
32+
value: old('handle', field.handle),
3333
required: true,
34-
errors: field.errors.get('handle'),
34+
errors: errors.get('handle'),
3535
data: {'error-key': 'handle'},
3636
disabled: readOnly,
3737
}) }}
@@ -42,8 +42,8 @@
4242
id: 'instructions',
4343
class: 'nicetext',
4444
name: 'instructions',
45-
value: field.instructions,
46-
errors: field.errors.get('instructions'),
45+
value: old('instructions', field.instructions),
46+
errors: errors.get('instructions'),
4747
data: {
4848
'error-key': 'instructions',
4949
},
@@ -54,19 +54,19 @@
5454
label: 'Use this field’s values as search keywords'|t('app'),
5555
id: 'searchable',
5656
name: 'searchable',
57-
on: field.searchable,
57+
on: old('searchable', field.searchable),
5858
disabled: readOnly,
5959
}) }}
6060

6161
{{ forms.customSelectField({
6262
label: "Field Type"|t('app'),
6363
instructions: "What type of field is this?"|t('app'),
64-
warning: (fieldId is not empty and not field.errors.has('type') ? "Changing this may result in data loss."|t('app')),
64+
warning: (fieldId is not empty and not errors.has('type') ? "Changing this may result in data loss."|t('app')),
6565
id: 'type',
6666
name: 'type',
6767
options: fieldTypeOptions,
68-
value: field is missing ? field.expectedType : className(field),
69-
errors: field.errors.get('type'),
68+
value: old('type', field is missing ? field.expectedType : className(field)),
69+
errors: errors.get('type'),
7070
data: {
7171
'error-key': 'type',
7272
},
@@ -91,7 +91,7 @@
9191
'language' in translationMethods ? { value: 'language', label: "Translate for each language"|t('app') },
9292
'custom' in translationMethods ? { value: 'custom', label: "Custom…"|t('app') }
9393
]|filter,
94-
value: field.translationMethodValue,
94+
value: old('translationMethod', field.translationMethodValue),
9595
toggle: true,
9696
targetPrefix: 'translation-method-',
9797
disabled: readOnly,
@@ -108,8 +108,8 @@
108108
id: 'translation-key-format',
109109
class: 'code',
110110
name: 'translationKeyFormat',
111-
value: field.translationKeyFormat,
112-
errors: field.errors.get('translationKeyFormat'),
111+
value: old('translationKeyFormat', field.translationKeyFormat),
112+
errors: errors.get('translationKeyFormat'),
113113
data: {'error-key': 'translationKeyFormat'},
114114
disabled: readOnly,
115115
}) }}

src/Http/Controllers/FieldsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use Illuminate\Contracts\View\View;
4444
use Illuminate\Http\JsonResponse;
4545
use Illuminate\Http\Request;
46+
use Illuminate\Validation\ValidationException;
4647
use ReflectionException;
4748
use ReflectionProperty;
4849
use Symfony\Component\HttpFoundation\Response;
@@ -184,7 +185,7 @@ public function store(Request $request): Response|CpScreenResponse
184185
if (! $this->fieldsService->saveField($field)) {
185186
Flash::error(t('Couldn’t save field.'));
186187

187-
return $this->edit($request, $field);
188+
throw ValidationException::withMessages($field->errors()->getMessages());
188189
}
189190

190191
if ($request->input('addAnother')) {

0 commit comments

Comments
 (0)