How to prevent tags from being deleted?


base map

I'm using twitter typeaheadjs to populate labels on a page. I want to prevent the token from being deleted when the token value is equal to the login id.

I get the event from the docs :

Before the item delete event:

$('input').on('beforeItemRemove', function(event) {
    alert("before item removed");
    var tag = event.item;
    if(tag == DataMixin.data.user.username){
        console.log('cannot delete agent');
    }else{
        console.log('agent deleted');
    }
 });

Event after item removal:

$('input').on('itemRemoved', function (event) {
    alert("item removed");
        }
    }
});

How to prevent tag removal based on above condition in typeaheadJS

Charlie

From the documentation:

event.cancel: set to true to prevent the item from being deleted

$('input').on('beforeItemRemove', function(event) {
    alert("before item removed");
    var tag = event.item;
    if(tag == DataMixin.data.user.username){
        event.cancel = true;
        console.log('cannot delete agent');
    }else{
        console.log('agent deleted');
    }
 });

Related


How to prevent blob container from being deleted?

Imre Purvill It is easy to create and delete blob data. There are ways to prevent accidental data loss, such as: Resource lock prevents accidental deletion of storage accounts Azure RBAC restricts access to accounts/keys. Soft deletes recover from accidental b

How to prevent blob container from being deleted?

Imre Purvill It is easy to create and delete blob data. There are ways to prevent accidental data loss, such as: Resource lock prevents accidental deletion of storage accounts Azure RBAC restricts access to accounts/keys. Soft deletes recover from accidental b

How to prevent objects from being deleted in Django?

Jill Bates I have a settings application in my project that uses a database table where each record represents a specific setting. And importantly, the settings must always be consistent, so I'm looking for a way to protect them from accidental deletion by adm

How to prevent objects from being deleted in Django?

Jill Bates I have a settings application in my project that uses a database table where each record represents a specific setting. And importantly, the settings must always be consistent, so I'm looking for a way to protect them from accidental deletion by adm

How to prevent blob container from being deleted?

Imre Purvill It is easy to create and delete blob data. There are ways to prevent accidental data loss, such as: Resource lock prevents accidental deletion of storage accounts Azure RBAC restricts access to accounts/keys. Soft deletes recover from accidental b

Prevent objects from being deleted

pudding When I have a class, I know that I can "protect" certain properties by using @propertyand @attr.deleterdecorators like this: class Foo: def __init__(self): self._attr = True @property def attr(self): return self._attr

Prevent objects from being deleted

pudding When I have a class, I know that I can "protect" certain properties by using @propertyand @attr.deleterdecorators like this: class Foo: def __init__(self): self._attr = True @property def attr(self): return self._attr

Prevent objects from being deleted

pudding When I have a class, I know that I can "protect" certain properties by using @propertyand @attr.deleterdecorators like this: class Foo: def __init__(self): self._attr = True @property def attr(self): return self._attr

Prevent objects from being deleted

pudding When I have a class, I know that I can "protect" certain properties by using @propertyand @attr.deleterdecorators like this: class Foo: def __init__(self): self._attr = True @property def attr(self): return self._attr

How to prevent commands from being deleted from history?

username I've noticed that when I use the arrow keys UPand traverse the command DOWN, if I edit the command afterwards, it will edit it in the history, I can even delete such a command, but I don't want it to have this effect commands in the history, so I don'

How to prevent commands from being deleted from history?

username I've noticed that when I use the arrow keys UPand traverse the command DOWN, if I edit the command afterwards, it will edit it in the history, I can even delete such a command, but I don't want it to have this effect commands in the history, so I don'

How to prevent files from being deleted when GAE is idle?

sh I have a Flask server running on GAE (Elastic Environment). The application generates certain files at runtime based on received API requests. But after the instance starts, after being idle, the files are lost. How can I prevent it? Lundin Custer Your appl

slurm: How to prevent job information from being deleted?

Alper Use sacctI want to get information about completed assignments. The answer mentions how we obtain job information. I submitted a job title with jobName.shjobID 176 . 12 hours later, new 200 jobs come in, I want to check my job (jobID=176) info and get sl

How to prevent files under user folder from being deleted?

scrapped How can I make some files not deleted by the user even under their home folder? Enzotinib It is possible to make the file undeletable, not even from the root directory on an ext2/3/4 filesystem, changing the filesystem attributes of the file: $ cd $ t

How can I prevent a directory from being deleted by the user?

pandia Suppose the directory was created dir1by sudoDesktop . sudo mkdir dir1 Then I apply chownand it chmodlooks like this: sudo chown root:root dir1 sudo chmod go-rwx dir1 Now dir1only accessible by owner root. $ ls -ld dir1 drwx------ 2 root root 4096 Jul

How to prevent Grails domain from being updated or deleted?

Jestrick After creating and saving the domain, I want to force the domain not to be updated or deleted. What is the easiest and most efficient way to achieve this? Jestrick One way to do this is to add a method in the Grails domain that both returns beforeUpda

How to prevent files under user folder from being deleted?

scrapped How can I make some files not deleted by the user even under their home folder? Enzotinib It is possible to make the file undeletable, not even from the root directory on an ext2/3/4 filesystem, changing the filesystem attributes of the file: $ cd $ t