bugfix with array types
This commit is contained in:
@@ -8,8 +8,8 @@
|
|||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@if($value !== '' || $editor === true)
|
@if($value !== '' || $editor === true)
|
||||||
<div x-data class="{{ twMerge('mb-4', $attributes->get('class')) }}">
|
<div x-data class="{{ twMerge('mb-4', $attributes->get('class')) }}" x-show="$store.files.length > 0 || {{ $editor === true ? 'true' : 'false' }}">
|
||||||
<h3 x-show="$store.files.length > 0 || {{ $editor === true ? 'true' : 'false' }}" class="text-xl font-semibold">{{ $label }}</h3>
|
<h3 class="text-xl font-semibold">{{ $label }}</h3>
|
||||||
<ul x-show="$store.files.length > 0" class="flex flex-col bg-white p-4 border border-gray-300 rounded-lg gap-4 mt-2">
|
<ul x-show="$store.files.length > 0" class="flex flex-col bg-white p-4 border border-gray-300 rounded-lg gap-4 mt-2">
|
||||||
<template x-for="file in $store.files" :key="file.name">
|
<template x-for="file in $store.files" :key="file.name">
|
||||||
<li class="flex items-center">
|
<li class="flex items-center">
|
||||||
@@ -50,22 +50,18 @@
|
|||||||
|
|
||||||
Alpine.store('files', []);
|
Alpine.store('files', []);
|
||||||
|
|
||||||
// Check if result is a string or a collection
|
// Check if each item in result is a string or an object
|
||||||
if (typeof result === 'string') {
|
result.forEach(item => {
|
||||||
result = result.split(',').filter((item) => item.length > 0);
|
if (typeof item === 'string') {
|
||||||
|
// If item is a string, get file details
|
||||||
Promise.all(result.map(fileName => new Promise(resolve => {
|
SM.mediaDetails(item, (details) => {
|
||||||
SM.mediaDetails(fileName, (details) => {
|
Alpine.store('files', [...Alpine.store('files'), details]);
|
||||||
resolve(details);
|
|
||||||
});
|
});
|
||||||
}))).then(detailsArray => {
|
} else {
|
||||||
Alpine.store('files', detailsArray);
|
// If item is an object, directly place it in the store
|
||||||
});
|
Alpine.store('files', [...Alpine.store('files'), item]);
|
||||||
|
}
|
||||||
} else if (Array.isArray(result)) {
|
});
|
||||||
// If result is a collection, directly place it in the store
|
|
||||||
Alpine.store('files', result);
|
|
||||||
}
|
|
||||||
|
|
||||||
const elem = document.getElementById('{{ $name }}');
|
const elem = document.getElementById('{{ $name }}');
|
||||||
if(elem) {
|
if(elem) {
|
||||||
|
|||||||
Reference in New Issue
Block a user