Laravel-Backpack / community-forum

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

[Editable Columns][Bug] - "editable_select" incompatibility with "exportOnlyField" #765

Closed not82 closed 10 months ago

not82 commented 10 months ago

Bug report

What I did

In an existing crud with some "exportOnlyField" set to true , I transformed a select field to a editable_select

What I expected to happen

Expected the editable_select to work properly

What happened

The field didn't work properly, I have a js error :

Uncaught TypeError: Cannot read properties of null (reading 'dataset')

spotting this king of line :

let hasDetailsRow = element.closest('.dataTable').dataset.hasDetailsRow === '1';

What I've already tried to fix it

Tried to remove some columns, and seen that fields with "exportOnlyField" are the origin of the error.

Is it a bug in the latest version of Backpack?

Yes

Backpack, Laravel, PHP, DB version

PHP VERSION:

PHP 8.1.26 (cli) (built: Nov 22 2023 10:01:32) (ZTS Visual C++ 2019 x64) Copyright (c) The PHP Group Zend Engine v4.1.26, Copyright (c) Zend Technologies with Zend OPcache v8.1.26, Copyright (c), by Zend Technologies with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans

LARAVEL VERSION:

10.33.0.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.2.2 backpack/crud: 6.3.2 backpack/editable-columns: 3.0.2 backpack/generators: v4.0.2 backpack/permissionmanager: 7.1.1 backpack/pro: 2.0.18 backpack/theme-coreuiv2: 1.2.2 backpack/theme-tabler: 1.1.1

karandatwani92 commented 10 months ago

Hey @not82 ,

If you are changing select to editable_select. You need to change the complete definition of the column, the required attributes are different.

The editable_select column requires an options attribute, which means the definitions for select_from_array & editable_select are equivalent. Docs here

Right now, you are mentioning a BUG related to exportOnlyField, So I tested it with the following:

 CRUD::column('select')
       ->type('editable_select')
       ->entity('category')
       ->options(\Backpack\NewsCRUD\app\Models\Category::all()->pluck('name', 'id')->toArray())
       ->exportOnlyField(true);

And this worked for me - No JS Error. Successful Export .✅

Hey @pxpm but I'm noticing a difference in the export output of select_from_array & editable_select.

Please put some light here🙏 Thanks

not82 commented 10 months ago

Hi @karandatwani92 ,

Sure I've seen there is different configuration. For the bug, it's another field ( in same crud ) that has exportOnlyField(true), it has no sens to have a column with both editable_select and exportOnlyField.. If you can't reproduce it, I'll try on my side to isolate the bug.

karandatwani92 commented 10 months ago

I agree, it makes no sense to have an editable_select column with exportOnlyField.

Let us know how to reproduce it, to fix it further! Meanwhile, I'm closing it. Feel free to reopen. Thanks