|
266 | 266 | pushVal: function() { |
267 | 267 | var self = this, |
268 | 268 | val = $.map(self.items(), function(item) { |
269 | | - return self.options.itemValue(item).toString(); |
| 269 | + //return self.options.itemValue(item).toString(); |
| 270 | + if(typeof self.options.itemValue(item) !== 'undefined'){ |
| 271 | + return self.options.itemValue(item).toString(); |
| 272 | + } |
| 273 | + else{ |
| 274 | + |
| 275 | + } |
270 | 276 | }); |
271 | 277 |
|
272 | 278 | self.$element.val(val, true).trigger('change'); |
|
280 | 286 |
|
281 | 287 | self.options = $.extend({}, defaultOptions, options); |
282 | 288 | // When itemValue is set, freeInput should always be false |
283 | | - if (self.objectItems) |
284 | | - self.options.freeInput = false; |
| 289 | + if (self.objectItems); |
| 290 | + //self.options.freeInput = false; //TRP 12/24/15 |
285 | 291 |
|
286 | 292 | makeOptionItemFunction(self.options, 'itemValue'); |
287 | 293 | makeOptionItemFunction(self.options, 'itemText'); |
|
369 | 375 | self.$input.focus(); |
370 | 376 | }, self)); |
371 | 377 |
|
372 | | - if (self.options.addOnBlur && self.options.freeInput) { |
373 | | - self.$input.on('focusout', $.proxy(function(event) { |
374 | | - // HACK: only process on focusout when no typeahead opened, to |
375 | | - // avoid adding the typeahead text as tag |
376 | | - if ($('.typeahead, .twitter-typeahead', self.$container).length === 0) { |
377 | | - self.add(self.$input.val()); |
378 | | - self.$input.val(''); |
379 | | - } |
380 | | - }, self)); |
381 | | - } |
| 378 | + if (self.options.addOnBlur && self.options.freeInput) { |
| 379 | + self.$input.on('focusout', $.proxy(function(event) { |
| 380 | + // HACK: only process on focusout when no typeahead opened, to |
| 381 | + // avoid adding the typeahead text as tag |
| 382 | + if ($('.typeahead, .twitter-typeahead', self.$container).length === 0) { |
| 383 | + self.add(self.$input.val()); |
| 384 | + self.$input.val(''); |
| 385 | + } |
| 386 | + }, self)); |
| 387 | + } |
382 | 388 |
|
383 | 389 | // Toggle the 'focus' css class on the container when it has focus |
384 | 390 | self.$container.on({ |
|
459 | 465 |
|
460 | 466 | var text = $input.val(), |
461 | 467 | maxLengthReached = self.options.maxChars && text.length >= self.options.maxChars; |
| 468 | + |
462 | 469 | if (self.options.freeInput && (keyCombinationInList(event, self.options.confirmKeys) || maxLengthReached)) { |
463 | 470 | // Only attempt to add a tag if there is data in the field |
| 471 | + //console.log("TRUE===self.options.freeInput && (keyCombinationInList(event, self.options.confirmKeys) || maxLengthReached)===FALSE"); |
| 472 | + |
464 | 473 | if (text.length !== 0) { |
465 | | - self.add(maxLengthReached ? text.substr(0, self.options.maxChars) : text); |
466 | | - $input.val(''); |
| 474 | + console.log("text.length !== 0"+text); |
| 475 | + //self.add(maxLengthReached ? text.substr(0, self.options.maxChars) : text); ////TRP 12/24/15 |
| 476 | + |
| 477 | + var item2 = self.$input.val(); |
| 478 | + if (self.objectItems) { |
| 479 | + var beforeFreeInputItemAdd = $.Event('beforeFreeInputItemAdd', { item: item2, cancel: true }); |
| 480 | + self.$element.trigger(beforeFreeInputItemAdd); |
| 481 | + if (beforeFreeInputItemAdd.cancel) |
| 482 | + return; |
| 483 | + |
| 484 | + console.log('beforeFreeInputItemAdd.item'); |
| 485 | + console.log(beforeFreeInputItemAdd.item); |
| 486 | + item2 = beforeFreeInputItemAdd.item; |
| 487 | + } |
| 488 | + |
| 489 | + self.add(item2); |
| 490 | + self.$input.val(''); |
| 491 | + // $input.val(''); //TRP 12/24/15 |
467 | 492 | } |
468 | 493 |
|
469 | 494 | // If the field is empty, let the event triggered fire as usual |
470 | 495 | if (self.options.cancelConfirmKeysOnEmpty === false) { |
| 496 | + //console.log("self.options.cancelConfirmKeysOnEmpty === false"); |
471 | 497 | event.preventDefault(); |
472 | 498 | } |
473 | 499 | } |
| 500 | + else{ |
| 501 | + //console.log("FALSE===self.options.freeInput && (keyCombinationInList(event, self.options.confirmKeys) || maxLengthReached)"); |
| 502 | + } |
474 | 503 |
|
475 | 504 | // Reset internal input's size |
476 | 505 | var textLength = $input.val().length, |
|
642 | 671 | * [13, {which: 188, shiftKey: true}] |
643 | 672 | */ |
644 | 673 | function keyCombinationInList(keyPressEvent, lookupList) { |
| 674 | + console.log('keyPressEvent'); |
| 675 | + console.log(keyPressEvent); |
| 676 | + console.log('lookupList'); |
| 677 | + console.log(lookupList); |
645 | 678 | var found = false; |
646 | 679 | $.each(lookupList, function (index, keyCombination) { |
647 | 680 | if (typeof (keyCombination) === 'number' && keyPressEvent.which === keyCombination) { |
648 | 681 | found = true; |
| 682 | + //console.log('line 657 found: true, return false'); |
649 | 683 | return false; |
650 | 684 | } |
651 | 685 |
|
|
655 | 689 | ctrl = !keyCombination.hasOwnProperty('ctrlKey') || keyPressEvent.ctrlKey === keyCombination.ctrlKey; |
656 | 690 | if (alt && shift && ctrl) { |
657 | 691 | found = true; |
| 692 | + //console.log('line 666 found: true, return false'); |
658 | 693 | return false; |
659 | 694 | } |
660 | 695 | } |
661 | 696 | }); |
662 | 697 |
|
| 698 | + //console.log('found: '); |
| 699 | + //console.log(found); |
663 | 700 | return found; |
664 | 701 | } |
665 | 702 |
|
|
0 commit comments