Laravel-Backpack / community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
28 stars 0 forks source link

[Bug] Dropzone will not accept upload if enclosed in custom_html #1187

Open btrumsey opened 2 days ago

btrumsey commented 2 days ago

Bug report

What I did

I'm formatting my CRUD form using custom_html field types that include <div> tags.

What I expected to happen

I expect that when I drag-and-drop an image into the dropzone, it will accept my upload.

What happened

A javascript error is thrown

{message: 'Cannot parse field name.', exception: 'Symfony\\Component\\HttpKernel\\Exception\\HttpException', file: '/home/btrumsey/dev/firstissues/vendor/laravel/framework/src/Illuminate/Foundation/Application.php', line: 1394, trace: Array(64)}

The error is caused by the fieldName value being provided in the POST request to upload the file, which will have a null for the data-repeatable-identifier value (e.g., null#image_front instead of items#image_front).

What I've already tried to fix it

The issue is in how the $dropzoneConfig.paramName value is calculated in dropzone.blade.php. The current implementation assumes that the node with the data-repeatable-identifier attribute will always be two levels up:

$dropzoneConfig.paramName = input.getAttribute('data-repeatable-input-name') !== null ? dz.parentNode.parentNode.getAttribute('data-repeatable-identifier') + '#' + input.getAttribute('data-repeatable-input-name') : input.getAttribute('name');

By adding the <div> tags, this is no longer the case and causes the error. I was able to fix this by using closest() instead of parentNode:

$dropzoneConfig.paramName = input.getAttribute('data-repeatable-input-name') !== null ? dz.closest('.repeatable-element').getAttribute('data-repeatable-identifier') + '#' + input.getAttribute('data-repeatable-input-name') : input.getAttribute('name');

Is it a bug in the latest version of Backpack?

I don't have the latest version of Pro, but I don't see any closed issues related to this issue.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

### PHP VERSION:
8.2.23

### PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, imagick, exif, mysqli, pdo_mysql, pdo_sqlite, Phar, posix, readline, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, Zend OPcache, xdebug

### LARAVEL VERSION:
11.26.0.0

### BACKPACK PACKAGE VERSIONS:
backpack/activity-log: 2.0.5
backpack/backupmanager: v5.0.5
backpack/basset: 1.3.6
backpack/crud: 6.7.38
backpack/devtools: 3.1.6
backpack/editable-columns: 3.0.10
backpack/generators: v4.0.6
backpack/logmanager: v5.0.2
backpack/medialibrary-uploaders: 1.2.0
backpack/menucrud: v4.0.2
backpack/pagemanager: 3.3.2
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.14
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.13
btrumsey commented 1 day ago

Renewed my Pro subscription and can confirm this is still present in the current version.