Search code examples
javascriptangularjsng-tags-input

ngTagsInput - Set onTagAdding callback


I'm trying to set a default function for the onTagAdding callback using the tagsInputConfig provider. No success.

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

All the other default options are set correctly, except for the callBacks. In the other hand, it works when I configure it as a property:

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

Is there any way to set a default function for this callback?


Solution

  • According to what I can tell from the documentation (tags-input.js && configuration.js) it appears that onTagAdding is not a default that you can specify.

    Per the source, here is the complete list that is available directly from the source code (PS: the keys for the object in the fourth argument are the names of the defaults):

    tagsInputConfig.load('tagsInput', $scope, $attrs, {
                    template: [String, 'ngTagsInput/tag-item.html'],
                    type: [String, 'text', validateType],
                    placeholder: [String, 'Add a tag'],
                    tabindex: [Number, null],
                    removeTagSymbol: [String, String.fromCharCode(215)],
                    replaceSpacesWithDashes: [Boolean, true],
                    minLength: [Number, 3],
                    maxLength: [Number, MAX_SAFE_INTEGER],
                    addOnEnter: [Boolean, true],
                    addOnSpace: [Boolean, false],
                    addOnComma: [Boolean, true],
                    addOnBlur: [Boolean, true],
                    addOnPaste: [Boolean, false],
                    pasteSplitPattern: [RegExp, /,/],
                    allowedTagsPattern: [RegExp, /.+/],
                    enableEditingLastTag: [Boolean, false],
                    minTags: [Number, 0],
                    maxTags: [Number, MAX_SAFE_INTEGER],
                    displayProperty: [String, 'text'],
                    keyProperty: [String, ''],
                    allowLeftoverText: [Boolean, false],
                    addFromAutocompleteOnly: [Boolean, false],
                    spellcheck: [Boolean, true]
                });
    

    tl;dr

    No you can't set a default function for the onTagAdding callback, but it could be a great issue to submit on their github!!!