ngTagsInput - Enable the onTagAdding feature

I've been attempting to establish a default function for the onTagAdding callback using the tagsInputConfig provider, but without any success.

tagsInputConfig.setDefaults('tagsInput', {
    placeholder: 'Search',
    maxTags: 10,
    minLength: 5,
    maxLength: 40,
    replaceSpacesWithDashes: false,
    onTagAdding: function (x,y,z) {
        debugger; // breakpoint is never called
    }
});

Although all the other default options are correctly configured, the callbacks remain ineffective. On the contrary, it works when set as a property:

<tags-input on-tag-adding="onTagAdding($tag)" ng-model="search"></tags-input>

Is there a method available to establish a default function for this particular callback?

Answer №1

If you want to set any function from your own scope as the callback, you can follow this example

# sample.html
<div ng-controller="MyController">
    <tags-input on-tag-adding="myCustomFunction($tag)" ng-model="search"></tags-input>
</div>

Then in your JavaScript file

angular.module('myModule').controller('MyController', function($scope) {
    $scope.myCustomFunction = function($tag) {
        console.log($tag);
        return false;
    };
});

I hope this explanation proves useful!

Answer №2

After reviewing the documentation (tags-input.js && configuration.js), it seems that the onTagAdding callback cannot be specified as a default.

The source code provides a list of available options (Note: keys in the object's fourth argument are default names):

tagsInputConfig.load('tagsInput', $scope, $attrs, {
                template: [String, 'ngTagsInput/tag-item.html'],
                type: [String, 'text', validateType],
                placeholder: [String, 'Add a tag'],
                ...
            });

tl;dr

It is not possible to set a default function for the onTagAdding callback, but you could consider submitting an issue on their github!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Formatting in Cx framework: Configuring right alignment and decimal precision on NumberField

Currently, I am involved in a project that involves UI development using Cx, a new FrontEnd framework based on React. You can find more information about Cx at One of the tasks in my project involves creating a Grid with filter fields located at the top ...

Web API 2 indicates the 405 Method Not Allowed error

After extensive research on various platforms including SO, I have made modifications to the Web.config based on recommendations to remove the WebDAV module and handler. Despite these changes, I am still encountering the following error: 405 Method Not Al ...

Delay in displaying image on bootstrap slider

I'm a beginner in JavaScript and currently learning the ropes. I have a bootstrap slider with images on each slide. My goal is to make the images appear with a slight delay on the slide where they belong. I've managed to achieve this for the firs ...

Click on the following link to view your screen resolution:

As I work on a website that showcases an animation with a resolution of 1024x768, I plan to distribute the link as a Holiday greeting through email. Is there a method to ensure that the website only loads in the specified resolution, even if the user' ...

When a function inside React uses this.props, it won't trigger the corresponding function

I am currently developing a Checklist using React and MaterialUI that consists of two components. One component is responsible for managing the data, while the other component allows for editing the data. However, I have encountered an issue where the func ...

When node.js v6.11.2 is installed on Windows 7, it does not include the correct npm version

When trying to install node.js v6.11.2 on my Windows 7 computer, I am encountering an issue where it is installing the incorrect version of npm alongside it. Even after downloading the installer directly from node.js' website which claims that 6.11.2 ...

Guide to retrieving a JSONArray using JavascriptInterface

I attempted to collect form data from an HTML using Javascript and send it back to Java as a JSONArray. However, I am encountering issues with the correct return of the JSONArray in the JavaScriptInterface. The JavaScript functions flawlessly in Chrome, i ...

Information in a Service is reset upon refreshing the page

After refreshing the page (e.g., by pressing F5), I noticed that the data in my service gets cleared. Is there a way to prevent this issue without using local storage? It's not a critical feature, but it does disrupt the application flow when users re ...

Angular JS: Automatically toggle the visibility of a div on a panel click event

There is a row, panel, and a closed div on load. Clicking on the panel should make the div appear while making the row and panel disappear. Clicking on X should make the panel and row appear again. <script src="https://ajax.googleapis.com/ajax/libs/ ...

When attempting to log out of Keycloak, a TypeError occurs in the front-end application stating that it cannot read properties of undefined related to the action of logging out

I've been trying to implement a logout feature in my front-end application using Keycloak, but I'm encountering difficulties. Most of the examples I found online are for older versions of Keycloak and use 'auth' and 'redirectURI&ap ...

Concentrate on the HTML element once it becomes active

I am facing a challenge where I need to focus on a specific input element. However, there is a spinner that appears on page load and remains hidden until certain http requests are completed. All inputs are disabled until the requests are finished. The setu ...

Jquery Banner Fade In animation malfunctioning

I am facing an issue with my banner on various browsers, especially IE 7,8, and possibly 9. When the fade-in effect is applied at the bottom of the banner, the shadows underneath turn black. Is there anyone who can help me resolve this issue? Website: ww ...

Can you explain the function of this.$nextTick()?

I'm a beginner with Vue.js and I'm trying to wrap my head around the logic of using nextTick in a method. I have two components set up like this: IsTuruIslem.vue <template> ... <t-row> <is-turu-islem-goruntule ref="isTuru ...

What is the best way to move between websites or pages without having to reload the current page using a selector?

Have you ever wondered how to create a webpage where users can navigate to other websites or pages without seeing their address, simply by selecting from a drop-down menu? Take a look at this example. Another similar example can be found here. When visit ...

When I modify the state in Vue.js, the two-way binding feature does not seem to function properly

I'm facing an issue with my dynamic array "slots" of objects which looks something like this: [{"availability": 1},{"availability": 3}] I render multiple inputs in Vue.js using v-for like so: <div v-for="slot in array"><input v-model="slot.av ...

Exploring the integration of Firebase with Next.js using getServerSideProps

I'm trying to retrieve the 'sample' document from Firestore using getServerSideProps only if a user is signed in. However, the current code I have isn't working and just returns 'can't read'. Is there a better solution or ...

Utilize jQuery to enclose nested elements within a parent element

There is a Markup presented below, where this HTML content is being generated from Joomla CMS. I am seeking a jQuery method to reorganize this HTML structure without modifying its PHP code. <div class="item column-1"> <div class="page-header"& ...

Having issues with json_decode not functioning correctly after using JSON stringify

After encoding a JavaScript array into JSON and posting it to PHP, I encountered an issue. Before posting the data, when I checked a value in the array using console.log(selection[878][2824]), I received the expected result. However, after encoding the var ...

Error: The PHP contact form is displaying field names instead of the actual values being entered

I am completely new to this and would appreciate some guidance. I have set up a contact form on a website, but I seem to be encountering some errors. Here is the email content I receive from the contact form: <p>$usersname has contacted you from you ...

Which file directory should I specify when using ng-include?

My project structure in Angular looks like this web server.py ##flask server program app static app.js controllers.js etc... templates index.html home.html In my index.ht ...