Skip to content

Commit 2c839cb

Browse files
authored
Merge pull request #3654 from Laravel-Backpack/fix-js-null-values
Fix repeatable converting non-string values to string when adding prefix
2 parents 6f0ddff + 6b5eb4f commit 2c839cb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,22 @@ function newRepeatableElement(container, field_group, values, position) {
281281
// this is different than using prefix in fields like text, number etc. In those cases the prefix is used
282282
// only for displaying purposes, when is set as `data-value-prefix` is when it is part of the value
283283
// like image field.
284-
let valuePrefix = $(this).data('value-prefix') ? $(this).data('value-prefix') : '';
284+
let prefix = $(this).data('value-prefix') ? $(this).data('value-prefix') : '';
285+
let value = values[$(this).data('repeatable-input-name')];
285286
286-
$(this).val(valuePrefix+values[$(this).data('repeatable-input-name')]);
287+
// only apply the prefix when the value is string and not empty.
288+
if(typeof value === 'string' && value.length && !value.startsWith("data:image/png;base64")) {
289+
value = prefix + value;
290+
}
291+
292+
$(this).val(value);
287293
288294
// if it's a Select input with no options, also attach the values as a data attribute;
289295
// this is done because the above val() call will do nothing if the options aren't there
290296
// so the fields themselves have to treat this use case, and look at data-selected-options
291297
// and create the options based on those values
292298
if ($(this).is('select') && $(this).children('option').length == 0) {
293-
$(this).attr('data-selected-options', JSON.stringify(values[$(this).data('repeatable-input-name')]));
299+
$(this).attr('data-selected-options', JSON.stringify(value));
294300
}
295301
}
296302
});

0 commit comments

Comments
 (0)