-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(chips): use empty chip buffer if not a string #9885
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,12 +383,15 @@ MdChipsCtrl.prototype.useOnSelectExpression = function() { | |
* model of an {@code md-autocomplete}, or, through some magic, the model | ||
* bound to any inpput or text area element found within a | ||
* {@code md-input-container} element. | ||
* @return {Object|string} | ||
* @return {string} | ||
*/ | ||
MdChipsCtrl.prototype.getChipBuffer = function() { | ||
return !this.userInputElement ? this.chipBuffer : | ||
this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue : | ||
this.userInputElement[0].value; | ||
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 : ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it ever possible for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it could happen if the developer uses a custom input element or for example the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed; I'm just wondering if we could alter this to cast the input to a string instead of returning an empty string. So, perhaps something like:
This will ensure that it is always a string, or the empty string, but should handle more cases. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought a lot about this, and figured that just returning an empty string is the safest & cleanest approach IMO I think casting would open more questions than it would solve, because then users might get weird chips like
|
||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this code was here from before, but it might be a good chance to get rid of the nested ternary expression since it's a little hard to read/follow. Also the
this.userInputElement[0].value
can be reduced tothis.userInputElement.val()
.