md-chips: Add a chip onInputBlur
I think it's a good experience for md-chips to convert outstanding text to a chip when input loses focus.
Here is a use-case when it's relevant. User does not know that he needs to click enter to add a chip. When users clicks "Send email", no email has been captured.

:+1:
:+1:
:+1:
:+1:
In the meantime, you can still hack :
MdChipsCtrl.prototype.onInputBlur = function () {
this.inputHasFocus = false;
var chipBuffer = this.getChipBuffer();
if (chipBuffer != "") { // REQUIRED, OTHERWISE YOU'D GET A BLANK CHIP
this.appendChip(chipBuffer);
this.resetChipBuffer();
}
};
This is just replicating what is triggered by ENTER keycode, on MdChipsCtrl.prototype.inputKeydown.
From the best I can tell, this is not explicitly specified in spec, but I would agree with the suggestion of the reporter.
UX decision: Always add on blur
Yay!
+1
I'm happy about your UX decision. Our users are having the same issues when filling out forms with chips. Looking forward to your fix :)
+1
+1
+1
+1
+1
+1
did anyone try out the hack @bonatoc mentioned here?
+1
@deepikat —Still works with the latest version (1.0.1 as of today)
In angular-material.js, look for MdChipsCtrl.prototype.onInputBlur
Here's the code again :
// ORIGINAL ANGULAR MATERIAL FUNCTION
// MdChipsCtrl.prototype.onInputBlur = function () {
// this.inputHasFocus = false;
// };
// - EOF - ORIGINAL ANGULAR MATERIAL FUNCTION
// CB HACK - AS OF 20160113
MdChipsCtrl.prototype.onInputBlur = function () {
this.inputHasFocus = false;
// ADDED CODE
var chipBuffer = this.getChipBuffer();
if (chipBuffer != "") { // REQUIRED, OTHERWISE YOU'D GET A BLANK CHIP
this.appendChip(chipBuffer);
this.resetChipBuffer();
}
// - EOF - ADDED CODE
};
// - EOF - CB HACK - AS OF 20160113
I've also implemented this hack successfully. However, is there a way to leave the source code alone and overwrite this from a separate file? I've messed around with priority/terminal properties, but cannot get it to work in a lot of cases.
@davidmillercode — Sure, that would be better, but for the moment my Javascript skills are... what they are.
As I understand it, AM is already writing/adding functions to directive controllers by extending prototype, so I guess a good Google/Stackoverflow/AM_Forums session should do the trick.
It seems logical that the directive's controller could be extended afterwards. You just need to find how to reference MdChipsCtrl from outside AM, after it is loaded. I'm sure a JS Jedi would find this trivial.
I proposed a hack just because I don't have time nor the skills to do things neatly yet.