Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Errors for relationship subfields are not detected to set the active tab correctly #5686

Closed
krjohnston opened this issue Oct 9, 2024 · 7 comments

Comments

@krjohnston
Copy link
Contributor

Bug report

What I did

Added tabbed panels for relationship with subfields in setupUpdateOperation

CRUD::field('inspectorAllocations')
    ->type('relationship')
    ->subfields([
        [
            'name' => 'inspector'
            'ajax' => true,
            'attribute' => 'reverse_full_name',
        ],
        [
            'name' => 'valid_date',
            'type' => 'date',
    ])
    ->tab('Inspector Allocations');

What I expected to happen

When the first error is on a relationship subfield, I expect that tab to be the active tab

What happened

The subfield was not recognised because the crud field in the array returned from $crud->getCurrentFields() is inspectorAllocations but the $fieldName under test is inspectorAllocations.0.name.

What I've already tried to fix it

I published show_tabbed_fields.blade.php and added a preg_split to obtain the parent name of any subfields before checking the array of available $fieldNames
This works for my case and does not have any adverse effect on standard format fieldNames

@php
    $horizontalTabs = $crud->getTabsType()=='horizontal' ? true : false;
    $tabWithError = (function() use ($crud) {
        if(! session()->get('errors')) {
            return false;
        }
        foreach(session()->get('errors')->getBags() as $bag => $errorMessages) {
            foreach($errorMessages->getMessages() as $fieldName => $messages) {

                # Transform subfield $fieldNames into the correct CRUD fieldName format 
                # preg_split by the array separator .digits. and take only the first element
                $fieldName = preg_split('/\.\d+\./',$fieldName)[0];

                if(array_key_exists($fieldName, $crud->getCurrentFields()) && array_key_exists('tab', $crud->getCurrentFields()[$fieldName])) {
                    return $crud->getCurrentFields()[$fieldName]['tab'];
                }
            }
        }
        return false;
    })();
@endphp

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud I am on 6.7.39 and the bug is still there.

Backpack, Laravel, PHP, DB version

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

PHP VERSION:

8.2.18

PHP EXTENSIONS:

Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, bcmath, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, igbinary, imagick, imap, intl, ldap, exif, msgpack, mysqli, pcov, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, readline, redis, shmop, SimpleXML, soap, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, memcached, swoole, Zend OPcache, xdebug

LARAVEL VERSION:

10.48.3.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.3.0
backpack/crud: 6.7.39
backpack/devtools: 3.1.0
backpack/editable-columns: 3.0.8
backpack/generators: v4.0.4
backpack/permissionmanager: 7.2.1
backpack/pro: 2.1.11
backpack/theme-tabler: 1.2.8

Copy link

welcome bot commented Oct 9, 2024

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use GitHub Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - GitHub Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@krjohnston krjohnston changed the title [Bug] Errors for relationship subfields are not detected to set the actlolplloolm; .l/ L:mu≥ tabbed panels for [Bug] Errors for relationship subfields are not detected to set the active tab correctly Oct 9, 2024
@karandatwani92
Copy link
Contributor

Hey @krjohnston

Yes, It does not take to the error field tab, but it highlights the tab where the error is with the details on top:

Screenshot 2024-10-13 at 8 35 28 PM

@krjohnston
Copy link
Contributor Author

krjohnston commented Oct 13, 2024 via email

@pxpm
Copy link
Contributor

pxpm commented Oct 14, 2024

Hey @krjohnston totally agree.

It's a simple change, are you willing to submit the PR for it, so you show up as a contributor since you already did all the work ?
If you don't have time/desire to do it, just let me know and I create the PR myself. 👍

Thanks for the heads up, and for providing the solution 🙏

@krjohnston
Copy link
Contributor Author

krjohnston commented Oct 14, 2024 via email

@pxpm
Copy link
Contributor

pxpm commented Oct 14, 2024

Hey @krjohnston thanks 🙏
You need to create a fork and pull the changes. 👍

@karandatwani92
Copy link
Contributor

Fixed here #5690

Thanks @krjohnston

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants