Laravel-Backpack / community-forum

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

[Bug] policy and report not accepted as array keys for editable_select options #798

Closed stemithy closed 8 months ago

stemithy commented 8 months ago

Bug report

What I did

Used the words "policy" and "report" as array keys that were assigned to the options of an editable_select column

What I expected to happen

I expected that when the column was set to "policy" or "report" the field would be updated and the options array value would display in the updated column.

What happened

The array key "policy" was simply ignored and when a column was set to that value, it defaulted to the first value in the array as if "policy" was not an array key. When set to "report" the list page threw an error and the list page would not display. Part of the error: (TypeError(code: 0): Illuminate\Foundation\Exceptions\Handler::report(): Argument #1 ($e) must be of type Throwable, App\Models\DMSDocument given, called in ......./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 666 at ....../vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:270)

What I've already tried to fix it

My current fix is to use "_policy" and "_report" as my array keys for options "Policy" and "Report". But I've tried clearing cache; composer updates; artisan publish; etc.

Is it a bug in the latest version of Backpack?

Yes After I run composer update backpack/crud the bug... is it still there? Yes

Backpack, Laravel, PHP, DB version

Backpack Pro 2.0.20, Laravel 10.40.0, PHP 8.2.14, MariaDB 5.5.68 When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.2.14 (cli) (built: Dec 28 2023 12:34:57) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.14, Copyright (c) Zend Technologies with Zend OPcache v8.2.14, Copyright (c), by Zend Technologies

LARAVEL VERSION:

10.40.0.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.2.2 backpack/crud: 6.5.1 backpack/editable-columns: 3.0.3 backpack/generators: v4.0.2 backpack/pro: 2.0.20 backpack/theme-coreuiv4: 1.1.1 backpack/theme-tabler: 1.2.0

stemithy commented 8 months ago

Just to clarify, when setting the options of an editable_select column: This triggers the bugs (works for a standard column, field or filter, just not for editable_select): 'options' => [ 'employment' => 'Employment', 'invoice' => 'Invoice', 'policy' => 'Policy', 'procedure' => 'Procedure', 'receipt' => 'Receipt', 'regulatory' => 'Regulatory', 'report' => 'Report', 'schedule' => 'Schedule', 'other' => 'Other', ]

This works without issue for editable_select: 'options' => [ 'employment' => 'Employment', 'invoice' => 'Invoice', '_policy' => 'Policy', 'procedure' => 'Procedure', 'receipt' => 'Receipt', 'regulatory' => 'Regulatory', '_report' => 'Report', 'schedule' => 'Schedule', 'other' => 'Other', ]

pxpm commented 8 months ago

Hey @stemithy thanks for the report, very easy to reproduce 🙏

I've just released editable-columns 3.0.4 with the fix for this.

Our private repo should pick the changes in a few time and make them available for download.

After upgrading to editable-columns 3.0.4 let me know if you are still experiencing the issue or we are good 🙏

Thanks

stemithy commented 8 months ago

Hey @stemithy thanks for the report, very easy to reproduce 🙏

I've just released editable-columns 3.0.4 with the fix for this.

Our private repo should pick the changes in a few time and make them available for download.

After upgrading to editable-columns 3.0.4 let me know if you are still experiencing the issue or we are good 🙏

Thanks

The issue remains after updating to editable-columns 3.0.4 https://flareapp.io/share/V7j9BgJP

I ran: composer update backpack/editable-columns composer update backpack/crud php artisan view:clear php artisan cache:clear php artisan config:clear php artisan route:clear composer dump-autoload

php artisan backpack:version

PHP VERSION:

PHP 8.2.14 (cli) (built: Dec 28 2023 12:34:57) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.14, Copyright (c) Zend Technologies with Zend OPcache v8.2.14, Copyright (c), by Zend Technologies

LARAVEL VERSION:

10.40.0.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.2.2 backpack/crud: 6.5.2 backpack/editable-columns: 3.0.4 backpack/generators: v4.0.2 backpack/pro: 2.0.21 backpack/theme-coreuiv4: 1.1.1 backpack/theme-tabler: 1.2.0

pxpm commented 8 months ago

Hey @stemithy I am pretty sure it's working so I spent a little bit more time looking at your issue and debugging your error stack trace.

I am sure something in the upgrade didn't went well in your side.

From your stack trace I can see that your field does not have the changes I made in the last release: image

image

Are you overwriting the file in your resources folder ? Can you check inside the vendor/backpack/editable-columns/resources/views/columns/editable_select.blade.php if you have the changes I am talking about ?

Cheers

stemithy commented 8 months ago

Hey @stemithy I am pretty sure it's working so I spent a little bit more time looking at your issue and debugging your error stack trace.

I am sure something in the upgrade didn't went well in your side.

Are you overwriting the file in your resources folder ? Can you check inside the vendor/backpack/editable-columns/resources/views/columns/editable_select.blade.php if you have the changes I am talking about ?

Cheers

Below is the version I have. I've tried uninstalling editable-columns, confirming that it was completely removed, and re-installing it. No change in the issue.

`{{-- custom editable column --}} @php $column['value'] = $column['value'] ?? data_get($entry, $column['name']);

if(is_callable($column['value']) && $column['value'] instanceof \Closure) {
    $column['value'] = $column['value']($entry);
}

if(is_callable($column['options']) && $column['options'] instanceof \Closure) {
    $column['options'] = $column['options']($entry);
}

$column['fake'] = $column['fake'] ?? false;
$column['store_in'] = $column['store_in'] ?? 'extras';

@endphp

<span data-column-type="text" data-column-editable="true" data-column-initial-value="{{ $column['value'] }}" data-column-events-registered="false" data-column-name="{{ $column['name'] }}" data-column-save-on-focusout="{{ $column['save_on_focusout'] ?? true }}" data-column-save-on-change="{{ $column['save_on_change'] ?? true }}" data-entry-id="{{ $entry->getKey() }}" data-route="{{ $column['route'] ?? url($crud->getRoute().'/minor-update') }}" data-text-color-unsaved="{{ $column['text_color_unsaved'] ?? '#869ab8' }}" data-on-error-text-color="{{ $column['on_error']['text_color'] ?? '#df4759' }}" data-on-error-text-color-duration="{{ $column['on_error']['text_color_duration'] ?? 0 }}" data-on-error-text-value-undo="{{ $column['on_error']['text_value_undo'] ?? false }}" data-on-success-text-color="{{ $column['on_success']['text_color'] ?? '#42ba96' }}" data-on-success-text-color-duration="{{ $column['on_success']['text_color_duration'] ?? 3000 }}" data-auto-update-row="{{ $column['auto_update_row'] ?? true }}" data-fake="{{ $column['fake'] ? $column['store_in'] : false }}" title="{{ __('backpack.editable-columns::minor_update.tooltip') }}">

@includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_start')
    <select
        name="{{ $column['name'] }}"
        data-focus="{{ $column['name'] }}"
        style="width: 100%; border: none; {{ ($column['underlined'] ?? true) ? "border-bottom: 1px dashed #abbcd5;" : "" }} background: none; text-overflow: ellipsis;"
        onfocus="registerMinorEditInputEvents(this, event)">
        @foreach($column['options'] as $value => $option)
            <option value="{{ $value }}" {{ $column['value'] == $value ? 'selected' : '' }}>{{ $option }}</option>
        @endforeach
    </select>
@includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_end')

`

pxpm commented 8 months ago

In that code you posted you have the updated version. But in the stack trace you posted you don't.

So if the code you posted is from the vendor/backpack/editable-columns/resources/columns it means you have the fixed version, but backpack is not using the file from the vendor folder, but rather the file from your resources/views/vendor/backpack/editable-columns/columns/editable_select.blade.php most probably.

I don't know the reason why you overwritten the package file, but you have 2 options: a) delete the file from resources/views/vendor/backpack/editable-columns/columns/editable_select.blade.php if you just published it there and didn't really changed nothing in the file. Backpack will automatically pick the file from the vendor folder. b) see the diff between the file in the vendor folder and the file in your resources folder and manually apply the changes in your file.

Please note that by overwriting the file in your resources folder you lose the ability to get automatic updates, so if you are not overwriting it for a good cause, just go with option a).

Hope it helps.

Cheers

stemithy commented 8 months ago

That was exactly the issue. All is working as expected now. Thanks for sticking with me! :)

Have a great weekend! Stephen