F
Filamentβ€’11mo ago
Husky110

Modify Builder Delete-Action

Heyho, I'm having a Builder that builds blocks which then on save contain data for multiple models. Right now I face two problems: 1.) Is there a way to require a confirmation before the delete-action on that block is performed? 2.) How can I access the block that is about to be deleted, so I can perform the appropriate database-operations? Thanks in advance. πŸ™‚
8 Replies
Husky110
Husky110β€’11mo ago
Thank you! Didn't see that part. πŸ™‚ But either I don't see what you mean or this only solves problem 1. Can you please elaborate on Problem 2?
awcodes
awcodesβ€’11mo ago
What db operations are you preforming? It’s a delete action so it deletes that item from the builder array. And when you save the form the builders field gets updated to the new array.
Husky110
Husky110β€’11mo ago
Hmm - I am maybe using the wrong component then? My scenario is that I build an admin-panel for some sort of quiz. I am using the Builder to manage the questions in a section, but those questions might be reused in another section. So when a user deletes a question, I want to remove it from the section aswell (hence the database operation). Plus every question has some additional data inside the builder that is question-specific (depending on the type).
awcodes
awcodesβ€’11mo ago
Something isn’t adding up in my head. I’m not seeing the relationship between a builder field and the other sections. I think there might be an underlying structural issue with what you are doing.
Husky110
Husky110β€’11mo ago
Okay - I'm trying to explain it. πŸ™‚ The overall purpose is to create a software that is used to certifiy users. I want my admins to be able to create new certifications. Those certifications are divided into sections, which themself have multiple questions. Each question has some data (like questiontext, etc.) and defines how the users answers it (via select, textinput, textarea, etc.) What I did was that I wrote a builder that is used in the editform of a section. The admin can click on the "add question"-button and use one of the predefined types. Let's say the admin chooses "TextInput", now the user can set the question text and some meta-data (min-length, max-length). After saving the section the array from the builder gets evaluated and every question is written inside its model, etc. Now when an admin deletes a question, the model has to be removed from the section and maybe has to be deleted completely (if it is not attached to any other section) and that is where my trouble starts... πŸ˜… (Edit: typos) I was hoping for a "direct" aproach on the delete-action itself. In the end I could compare on the handleRecordUpdate what the array gave me and what is stored inside the db.
awcodes
awcodesβ€’11mo ago
yea, i'm not sure how'd you do that with your setup. This should all be relationships and not data injection in to the other sections. sorry
Husky110
Husky110β€’11mo ago
no worries - I'll evaluate output of "sync" between section and question and there I see what's missing. πŸ™‚ thank you anyhow πŸ™‚