Created
June 11, 2014 20:03
-
-
Save thinkjones/0e0b7d2260413b0697ca to your computer and use it in GitHub Desktop.
Kendo Angular MultiSelect With Ability to Add New Items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| angular.module('mainUI') | |
| .directive('multiSelectDropdown', function () { | |
| function validateAddingOfItem(value, scope) { | |
| scope.errorMessage = ""; | |
| return true; | |
| } | |
| return { | |
| restrict: 'E', | |
| templateUrl : 'directives/multiSelectDropdown.html', | |
| require: 'ngModel', | |
| scope: { | |
| ngModel: '=', | |
| dropdownType: '=', | |
| placeholder: '@' | |
| }, | |
| replace: true, | |
| transclude: false, | |
| link: function(scope, elem, attr, ctrl) { | |
| var tags = []; | |
| var newitemtext; | |
| scope.itemsOptions = { | |
| placeholder: "The placeholder", | |
| change: function() { | |
| $('#tags_taglist li span:first-child').each(function() { | |
| $(this).text($(this).text().replace(" (Add New)", "")); | |
| }); | |
| }, | |
| dataBound: function() { | |
| if((newitemtext || this._prev) && newitemtext != this._prev) | |
| { | |
| newitemtext = this._prev; | |
| var dataitems = this.dataSource.data(); | |
| for (var i = 0; i < dataitems.length; i++) { | |
| var dataItem = dataitems[i]; | |
| if(dataItem.value != dataItem.text) { | |
| this.dataSource.remove(dataItem); | |
| } | |
| } | |
| dataitems = this.dataSource.data(); | |
| var found = false; | |
| for (var i = 0; i < dataitems.length; i++) { | |
| var dataItem = dataitems[i]; | |
| if(dataItem.value == newitemtext) { | |
| found = true; | |
| } | |
| } | |
| if(!found) | |
| { | |
| this.dataSource.add({text: newitemtext + " (Add New)", value: newitemtext}); | |
| this.open(); | |
| } | |
| } | |
| }, | |
| dataTextField: "text", | |
| dataValueField: "value", | |
| animation: false | |
| } | |
| scope.itemsDataSource = new kendo.data.DataSource({data: []}); | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment