⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Conditional delete/deactivate?



Kobus
  • profile picture
  • Member

Posted 31 August 2014 - 17:43 PM

Hi all,

 

Just a quick question, hoping someone has done this before:

 

1. I have a table called "security_questions" which contains like 20 or so security questions that users can choose when they register on my side.

2. I have used Grocery CRUD for admins to manage the questions.

3. When users choose their security questions on signup, a separate table "user_security_questions" is populated with their question ID and their respective answers.

4. I want to be able to prevent deletion/deactivation of an item that is in use by any user.

 

Is there a quick way to do this? Anybody done similar things before? I am thinking a callback "before delete" and then check if the ID is in use, then return false if so, but perhaps there is something better, such as not showing the delete icon in the first place in list view?

 

The alternative to finding a way to delete the item in the "user_security_question" at the time of delete via a callback is not ideal, because in the event of there being only one security question, the user's security question will be deleted.

 

Any ideas will be appreciated!

 

Kind regards,

 

Kobus

 


Amit Shah
  • profile picture
  • Member

Posted 04 September 2014 - 03:52 AM

Hi there - yes you thought in the right direction to use callback before delete - but since you want to control where you want to show the delete button - you may do the following

unset the delete functionality for the crud

add an extra column stating something like user action or whatever suites it

make a callback to the column

there - match the condition for the id - if it is in use - just return blank or return with a buttonized href to delete the element.

You may garnish the solution with javascript hooked to the button class (you may give 1 unique class name to connect to each) on click of which it pops up like actual delete button

 

Hope this works out

 

Happy GCing :)