material icon indicating copy to clipboard operation
material copied to clipboard

md-chips: Add a chip onInputBlur

Open websirnik opened this issue 11 years ago • 61 comments

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.

2015-06-19 11_35_02

websirnik avatar Jun 19 '15 10:06 websirnik

:+1:

jproby avatar Jun 23 '15 09:06 jproby

:+1:

nitinhayaran avatar Jul 02 '15 06:07 nitinhayaran

:+1:

reillydavis avatar Jul 02 '15 06:07 reillydavis

:+1:

Nikesh avatar Jul 05 '15 11:07 Nikesh

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.

bonatoc avatar Aug 05 '15 11:08 bonatoc

From the best I can tell, this is not explicitly specified in spec, but I would agree with the suggestion of the reporter.

jestelle avatar Aug 12 '15 20:08 jestelle

UX decision: Always add on blur

jelbourn avatar Aug 12 '15 23:08 jelbourn

Yay!

bonatoc avatar Aug 14 '15 00:08 bonatoc

+1

zzo avatar Sep 11 '15 18:09 zzo

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 :)

maelfrize avatar Oct 13 '15 09:10 maelfrize

+1

janvandenberg avatar Oct 27 '15 13:10 janvandenberg

+1

alphatwit avatar Nov 25 '15 20:11 alphatwit

+1

MaximShoustin avatar Nov 27 '15 16:11 MaximShoustin

+1

davidmillercode avatar Nov 30 '15 20:11 davidmillercode

+1

treyhoover avatar Dec 10 '15 15:12 treyhoover

+1

nicolac18 avatar Dec 18 '15 12:12 nicolac18

did anyone try out the hack @bonatoc mentioned here?

+1

deepikat avatar Jan 13 '16 01:01 deepikat

@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

bonatoc avatar Jan 13 '16 11:01 bonatoc

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 avatar Jan 13 '16 20:01 davidmillercode

@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.

bonatoc avatar Jan 14 '16 06:01 bonatoc