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

HasMany field Items not deleted after Form validation fails #5820

Open
alexoleynik0 opened this issue Sep 14, 2023 · 0 comments
Open

HasMany field Items not deleted after Form validation fails #5820

alexoleynik0 opened this issue Sep 14, 2023 · 0 comments

Comments

@alexoleynik0
Copy link

  • Laravel Version: 9.50.2
  • PHP Version: 8.0.2
  • Laravel-admin: 1.8.19

Description:

Assuming you have a Form with HasMany field used, and you decided to delete already existing Item from there, but Form validation failed somewhere - on the second render you won't see those Items you previously removed, but if Form submission now succeeds you will get that removed item back as it won't be passed with form data to be removed on the second time.

Steps To Reproduce:

  • Create Form with HasMany field, create some Items and save.
  • Open that main Instance to Edit, make some changes to invalidate form (leave required field empty for example).
  • Remove one of the HasMany Items.
  • Submit form, see validation errors. Notice that you don't see removed HasMany Item.
  • Fix validation errors and submit the From again.
  • Now the supposedly removed HasMany Item appears in the Form again, as it is not removed.

I assume the solution could be in the HasMany::buildRelatedForms method on the lines where it skips Items that has remove_flag checked. Maybe there should be some check if that Item has ID and then render only hidden input with remove_flag for that Item, so it could be removed on valid Form submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant