Reputation: 15337
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?
Upvotes: 1
Views: 2450
Reputation: 163
You can define any function from your scope to be the callback, here's an example
# test.html
<div ng-controller="MyCtrl">
<tags-input on-tag-adding="myFunction($tag)" ng-model="search"></tags-input>
</div>
And in js file
angular.module('myModule').controller('MyCtrl', function($scope) {
$scope.myFunction = function($tag) {
console.log($tag);
return false;
};
});
Hope it helps!
Upvotes: 2
Reputation: 6430
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]
});
Upvotes: 1