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] CRUD field JS Does Not Play Nicely When Sorting Repeatable #5482

Open
zachweix opened this issue Mar 27, 2024 · 2 comments
Open

[Bug] CRUD field JS Does Not Play Nicely When Sorting Repeatable #5482

zachweix opened this issue Mar 27, 2024 · 2 comments
Assignees

Comments

@zachweix
Copy link
Contributor

Bug report

What I did

I added a rule in a repeatable crud field with a subfield

crud.field('rules').subfield('always_active').onChange(function(field) {
	if (field.value == 1) {
		crud.field('zmanim').subfield('when_to_show', field.rowNumber).hide();
	} else {
		crud.field('zmanim').subfield('when_to_show', field.rowNumber).show();
	}
}).change();

I then added more rows to the repeatable field and rearranged them.

What I expected to happen

Changing "always_active" shows/hides "when_to_show" on the same row.

What happened

Changing "always_active" shows/hides "when_to_show" on a different row.

What I've already tried to fix it

I've tried tweaking the repeatable blade file, but was unable to find the source of the problem. Essentially, when we are creating the rule, we are binding the specific field being edited to a row number. If instead we either bind a row number edited to a row number or if we bind the field to its neighbor, no matter the row - either option should fix it, I just couldn't think of the best way to do that

Is it a bug in the latest version of Backpack?

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

Backpack, Laravel, PHP, DB version

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

PHP VERSION:

PHP 8.3.2-1+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Jan 20 2024 14:16:40) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
with Zend OPcache v8.3.2-1+ubuntu22.04.1+deb.sury.org+1, Copyright (c), by Zend Technologies
with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

LARAVEL VERSION:

11.0.7.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.3.0
backpack/crud: 6.7.0
backpack/editable-columns: 3.0.1
backpack/generators: v4.0.4
backpack/pro: 2.1.8
backpack/theme-tabler: 1.2.8

@karandatwani92
Copy link
Contributor

karandatwani92 commented Mar 28, 2024

Hey @zachweix
Your code works perfectly:

crud.field('features').subfield('quantity').onChange(function(field) {
    if (field.value == 0) {
		crud.field('features').subfield('value', field.rowNumber).hide();
	} else {
		crud.field('features').subfield('value', field.rowNumber).show();
	}
}).change();

chrome-capture-2024-2-28

BUT after reordering, the row number stays the same & causes the BUG:
chrome-capture-2024-2-28 (1)

I have assigned my colleague to fix it. Thanks for reporting.

@zachweix
Copy link
Contributor Author

Thank you very much!

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

No branches or pull requests

3 participants