251 Posts
Viktor Iwan
7 years ago
4
Topic

Hello,

I create a list which has delete button in it. By default, it is already has pop-up confirmation. But i need to validate as well if the data is used in other content type (Related Field/Foreign Key). 


So, if it still being use.. it will display something like "Delete cancelled, please remove data from xxxx first"

Any insight on how to do this ?

Get a VIP membership
4229 Posts
Kadministrator
7 years ago
0
Level 1

I think you could use beforeStore code field and do check there.Or using some custom ajax validation function that would run on button click.

35 Posts
julien
7 years ago
2
Level 1

Hi, i have the same behavior in my web app and i use a code before render field on my list view "periode" as say Klas:

I've two content :

- periode (in english period)

- stage (in english traineship)

In the content stage i have a field stage_periode (int, id of the periode), so the two content are link by this field.

If a stage is store in a periode content my users can't delete the periode. I alert by ('You can't delete periode because they are XX stages stored'):

I share my code:

/** Nombre de stages (BeforeRender of list periode)*/
$db1 = JFactory::getDbo();
$query = $db1->getQuery(true);
$query->select($db1->quoteName(array('stage_periode')));
$query->from($db1->quoteName('l1_cck_store_form_stage'));
$query->where($db1->quoteName('stage_periode')." LIKE ".$fields['art_id']->value);
$db1->setQuery($query);
$stages = $db1->loadRowList();
$nb_stages =strval( count($stages));
$supr_alert="'Vous ne pouvez pas supprimer cette période. Il y a ".$nb_stages." stages enregistrés sur cette période'";
if(count($stages)!=0){
$fields['icon_trash']->typo='<a href="javascript: void(0);" onclick="alert('.$supr_alert.');"><i></i></a>';
}else{

//Do nothing (link delete seblod)

}

/***********************************************/

icon_trash is a field on the list "periode" who have the link DELETE (button 2 seblod). So if they are 0 stage i don't override the field icon-trash

Voilà

251 Posts
Viktor Iwan
7 years ago
1
Level 2

So you basically disable the delete function before it getting triggered

35 Posts
julien
7 years ago
0
Level 3

I disable the delete function before the render of the list

Get a VIP membership