md-chips on blur not working in angular-material 1.1.0

Rahul Kiwitech
Rahul K...
Participant
292 Points
26 Posts

I am using md-chips in angular-material 1.1.0. But on blur not working. 

<md-chips name="sendTo" class="sendTo" ng-model="CMessage.To" ng-init="keys=[13,188]" md-separator-keys="keys" placeholder="Enter an email address" type="email" md-transform-chip="chipValidation($chip)" md-require-match="true" md-add-on-blur="true"></md-chips>

Although I set true as:

md-add-on-blur="true"
When I changed it to version 1.1.3 , it is working fine  but some drop downs are not working.
Because angular-material.js had some changes since the 1.1.0 rc5 version,
So if we do not have a `value` or `ng-value`, assume it is an empty option which clears the select.
You can see more details here: https://github.com/angular/material/commit/fcd42df882a1a1a1a83473204febf4ece6c5d332

Can any one fix this problem?

Thanks...

Views: 10122
Total Answered: 4
Total Marked As Answer: 2
Posted On: 29-Mar-2017 22:54

Share:   fb twitter linkedin
Answers
guest1
guest1
Member
10 Points
0 Posts
         

ngBlur and ngFocus will start working from 1.1.1 version of Angular Material
We just need to add md-no-cache="true"

Posted On: 30-Mar-2017 05:13
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Hi guys,

I think, it's a bug. You can see more details for this change here:
https://github.com/angular/material/issues/3364

Here you can see solution as:
Replace following code

MdChipsCtrl.prototype.onInputBlur = function () {
   this.inputHasFocus = false;
};

with

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.

Posted On: 30-Mar-2017 05:21
Smith
Smith
None
2568 Points
74 Posts
         

Here is how to implement the hack without changing the source code. we simply need to extend the mdChips directive and you can implement it from there. Here is sample code as:

angular.module('myApp').directive('mdChips', function () {
  return {
    restrict: 'E',
    require: 'mdChips', // Extends the original mdChips directive
    link: function (scope, element, attributes, mdChipsCtrl) {
      mdChipsCtrl.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
      };
    }
  }
});
Posted On: 30-Mar-2017 05:26
Rahul Kiwitech
Rahul K...
Participant
292 Points
26 Posts
         

Thanks.

Posted On: 30-Mar-2017 05:30
 Log In to Chat