Skip to content

Commit 446e04f

Browse files
authored
Merge pull request #3538 from Laravel-Backpack/add-prefix-in-repeatable-fields-that-need-them
prefixes in repeatable fields that need them
2 parents c7cd372 + a2826fc commit 446e04f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/resources/views/crud/fields/image.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function maximumServerUploadSizeInBytes() {
8989
<div class="btn-group">
9090
<div class="btn btn-light btn-sm btn-file">
9191
{{ trans('backpack::crud.choose_file') }} <input type="file" accept="image/*" data-handle="uploadImage" @include('crud::fields.inc.attributes')>
92-
<input type="hidden" data-handle="hiddenImage" name="{{ $field['name'] }}" value="{{ $value }}">
92+
<input type="hidden" data-handle="hiddenImage" name="{{ $field['name'] }}" data-value-prefix="{{ $field['prefix'] }}" value="{{ $value }}">
9393
</div>
9494
@if(isset($field['crop']) && $field['crop'])
9595
<button class="btn btn-light btn-sm" data-handle="rotateLeft" type="button" style="display: none;"><i class="la la-rotate-left"></i></button>

src/resources/views/crud/fields/repeatable.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ function newRepeatableElement(container, field_group, values) {
217217
// set the value on field inputs, based on the JSON in the hidden input
218218
new_field_group.find('input, select, textarea').each(function () {
219219
if ($(this).data('repeatable-input-name')) {
220-
$(this).val(values[$(this).data('repeatable-input-name')]);
220+
221+
// if the field provides a `data-value-prefix` attribute, we should respect that and add that prefix to the value.
222+
// this is different than using prefix in fields like text, number etc. In those cases the prefix is used
223+
// only for displaying purposes, when is set as `data-value-prefix` is when it is part of the value
224+
// like image field.
225+
let valuePrefix = $(this).data('value-prefix') ?? '';
226+
227+
$(this).val(valuePrefix+values[$(this).data('repeatable-input-name')]);
221228
222229
// if it's a Select input with no options, also attach the values as a data attribute;
223230
// this is done because the above val() call will do nothing if the options aren't there

0 commit comments

Comments
 (0)