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] In Relationship field nested subfields doesn't work #5761

Open
Zeno97 opened this issue Jan 28, 2025 · 3 comments
Open

[Bug] In Relationship field nested subfields doesn't work #5761

Zeno97 opened this issue Jan 28, 2025 · 3 comments
Labels

Comments

@Zeno97
Copy link

Zeno97 commented Jan 28, 2025

Bug report

Please note: All issues must be submitted in English. If not, they will be closed automatically.

What I did

I've defined an HasMany relationship between fields where one of them is another relationship field with subfields

What I expected to happen

It should show subfields

What happened

Uncaught SyntaxError: "undefined" is not valid JSON

What I've already tried to fix it

Actually nothing

Is it a bug in the latest version of Backpack?

Yes

Backpack, Laravel, PHP, DB version

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

PHP VERSION:

8.4.1

PHP EXTENSIONS:

Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, json, FFI, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, intl, SPL, ldap, mbstring, session, standard, mysqlnd, mysqli, odbc, pcntl, PDO, pdo_dblib, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, random, readline, Reflection, exif, shmop, SimpleXML, snmp, soap, sockets, sodium, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, xdebug, Zend OPcache

LARAVEL VERSION:

11.37.0.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.3.6
backpack/calendar-operation: 1.0.12
backpack/crud: 6.7.45
backpack/generators: v4.0.7
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.30
backpack/theme-coreuiv4: 1.1.5

Additional Information

Here's some more info that could be helpful in reproducing or debugging:

  • Environment details (e.g., operating system, web server, browser): ??
  • Relevant error logs or screenshots (if any): ??

Image

Note: Issues that cannot be reproduced or lack necessary details to diagnose could be closed.

@Zeno97 Zeno97 added the triage label Jan 28, 2025
Copy link

welcome bot commented Jan 28, 2025

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

Copy link

Based on the information provided in your bug report, it appears you're experiencing an issue with nested subfields in a Relationship field in Backpack. This is indeed a known limitation in Backpack.

The current implementation of the Relationship field in Backpack does not fully support nested subfields, especially when one of the subfields is another relationship field with its own subfields. This limitation is documented in several GitHub issues for the Backpack CRUD repository.

For example, in Github Issue #4109, there's a comprehensive discussion about which field types work as subfields inside relationship fields. The issue notes that not all field types are fully supported as subfields, and there can be unexpected behavior or errors when using complex nested structures.

The error you're seeing ("Uncaught SyntaxError: "undefined" is not valid JSON") suggests that there might be a problem with how the nested data is being processed or rendered in the JavaScript layer of the Backpack interface.

Unfortunately, the knowledge sources don't provide a direct solution for this specific issue. However, here are a few suggestions based on similar issues:

  1. Try simplifying your field structure. If possible, avoid nesting relationship fields within other relationship fields.

  2. Check if there are any recent updates to Backpack that might address this issue. You're using a relatively recent version (6.7.45), but it's always worth checking if there's a newer version available.

  3. If you need this specific structure, you might need to consider creating a custom field type that can handle the nested relationships in the way you need.

  4. Report this specific issue on the Backpack GitHub repository, providing a minimal reproducible example. The Backpack team is usually responsive to bug reports and might be able to provide a workaround or fix.

If you need further assistance, I'd recommend opening a new issue on the Backpack CRUD GitHub repository with a detailed description of your field structure and a minimal code example that reproduces the issue. This will allow the Backpack team to investigate and potentially provide a more specific solution.

ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️

Relevant sources:

Github Issue (open): [Bug] Backpack does not guess attributes in subfields
Github Issue (closed): [Bug] Field relationship_select causes QueryException when validation fails.
Github Issue (closed): [Bug] Update Trait: bad array key checking $field['subfield']
Github Issue (closed): [Bug] Errors for relationship subfields are not detected to set the active tab correctly
Github Issue (closed): ErrorException Undefined array key "subfields"
Github Issue (closed): [v5][Summary] Not all fields work as subfields inside relationship
Github Issue (closed): [4.2][Bug] Relationships don't get saved for subfields
Github Issue (closed): [Bug] FakeFields: Undefined array key "model"
Support QA
Github Issue (closed): [Bug] options attribute ignored in relationship field type
Github Issue (closed): [Bug] relations field don`t work with resolveRelationUsing method
Github Issue (closed): [4.2][Bug] Fake subfields do not get saved
Github Issue (closed): [Feature or Documentation Request] - CrudField JavaScript Library with relationship/subfield fields

@karandatwani92
Copy link
Contributor

Hey @Zeno97

You can see the Repeatable field working with subfields used with hasmany relationship here at Invoice CRUD of the demo.

Its implementation code can be seen in the demo repo for help:

I was unable to reproduce the issue. Let me know if I missed something.

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

No branches or pull requests

2 participants