error inside onInputBlur, when using md-chips with md-autocomplete
Actual Behavior:
What is the issue? *Click inside the chips input. Then click outside to blur. It throws an error.What is the expected behavior?shouldn't throw error on blur
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:http://codepen.io/ex37/pen/jrQkvrDetails:This demo is a part of Angular Material's documentation. This problem was introduced in version 1.1.1, and was not there before.
Angular Versions: *
Angular Version:1.5.6Angular Material Version:1.1.1
Additional Information:
Browser Type: *ChromeBrowser Version: *54.0.2840.59 (64-bit)OS: *macOS SierraStack Traces:
angular-material.min.js:14 Uncaught TypeError: Cannot read property 'trim' of null(…)
e.onInputBlur @ angular-material.min.js:14
(anonymous function) @ angular.js:1256
Qf @ angular.js:3456
d @ angular.js:3444
Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.
Do not modify the titles or questions. Simply add your responses to the ends of the questions. Add more lines if needed.
A possible solution is to change line https://github.com/angular/material/blob/master/src/components/chips/js/chipsController.js#L534 to
var chipBuffer = this.getChipBuffer();
chipBuffer = chipBuffer && chipBuffer.trim();
A similar problem is possibly on this line, https://github.com/angular/material/blob/master/src/components/chips/js/chipsController.js#L153 trim is done when appending, but it should be done before this check
if ((this.autocompleteCtrl && this.requireMatch) || !chipBuffer) return;
Another thing I was thinking about, the logic of using trim() assumes, that only a string value can be returned by the chipBuffer function. I am not sure if it's always like that. Another thing is, if this is something returned by the input's ngModel, then it is always trimmed by default in angular, so no need to trim at all.
@ex37 I'm facing the similar problem what changes do i have to do ?
@LabN36 you can find their fix here: https://github.com/angular/material/pull/9885/commits/4c0c7f9cc0fa7f24a108b08d849cf905183e6451
in short, replace code for MdChipsCtrl.prototype.getChipBuffer with this
MdChipsCtrl.prototype.getChipBuffer = function() {
var chipBuffer = !this.userInputElement ? this.chipBuffer :
this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
this.userInputElement[0].value;
// Ensure that the chip buffer is always a string. For example, the input element buffer might be falsy.
return angular.isString(chipBuffer) ? chipBuffer : '';
};
Thanks Very much it's fixed :+1: