Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

chips: editable mdChip not working properly #10879

Closed
tairmansd opened this issue Aug 31, 2017 · 0 comments · Fixed by #11323
Closed

chips: editable mdChip not working properly #10879

tairmansd opened this issue Aug 31, 2017 · 0 comments · Fixed by #11323
Assignees
Labels
has: Pull Request A PR has been created to address this issue P2: required Issues that must be fixed. resolution: fixed severity: regression This issue is related to a regression type: bug
Milestone

Comments

@tairmansd
Copy link

Issue:
I found out that the editable functionality of md-chip is not working properly. Every time I try to edit the value of a chip it'll disappear.

Steps to reproduce the issue:

  • Go to the "Make chips editable." section of site: https://material.angularjs.org/latest/demo/chips
  • Then type fruit name in text box.
  • Navigate to any chip using left and right arrow.
  • press space to make it editable
  • type new value or change the existing one
  • press enter the newly created chip will disappear.

Additional Information:

  • Browser Type: Chrome*
  • Browser Version: 60.03*
  • OS: Windows 10*

What I found is the problem is with this piece of code in angular-material.js at line number 26743.
MdChipCtrl.prototype.getContentElement = function() { return angular.element(this.getChipContent().children()[0]); };

this.getChipContent().children() becomes empty, and doesn't return the first child element which is text label that contains the user inputted value as a result var content = this.getContentElement().text(); at line number 26766 returns empty string.

MdChipCtrl.prototype.goOutOfEditMode = function() {
  if (!this.isEditting) return;

  this.isEditting = false;
  this.$element.removeClass('_md-chip-editing');
  this.getChipContent()[0].contentEditable = 'false';
  var chipIndex = this.getChipIndex();

  var content = this.getContentElement().text();
  if (content) {
    this.parentController.updateChipContents(
        chipIndex,
        this.getContentElement().text()
    );

    this.$mdUtil.nextTick(function() {
      if (this.parentController.selectedChip === chipIndex) {
        this.parentController.focusChip(chipIndex);
      }
    }.bind(this));
  } else {
 **//THIS CODE EXECUTES RESULTING IN DELETION OF CHIP FROM THE MODEL**
    this.parentController.removeChipAndFocusInput(chipIndex);
  }
};

Solution:
MdChipCtrl.prototype.getContentElement = function() { return angular.element(this.getChipContent().first); };*

@Splaktar Splaktar changed the title Editable mdChip not working properly. chips: editable mdChip not working properly Jun 11, 2018
@Splaktar Splaktar self-assigned this Jun 11, 2018
@Splaktar Splaktar added type: bug P2: required Issues that must be fixed. severity: regression This issue is related to a regression labels Jun 11, 2018
@Splaktar Splaktar added this to the 1.1.10 milestone Jun 11, 2018
Splaktar added a commit that referenced this issue Jun 11, 2018
use jQuery's `contents()` instead of `children()`
since the chip content elements are text nodes
and `children()` doesn't find text nodes
improve double click detection when editable chips are enabled
add/improve JSDoc and types
rename `MdChipCtrl.isEditting` to `MdChipCtrl.isEditing`

Fixes #11298. Fixes #10392. Fixes #10532. Fixes #10664. Fixes #10879.
Splaktar added a commit that referenced this issue Jun 17, 2018
use jQuery's `contents()` instead of `children()`
since the chip content elements are text nodes
and `children()` doesn't find text nodes
improve double click detection when editable chips are enabled
add/improve JSDoc and types
rename `MdChipCtrl.isEditting` to `MdChipCtrl.isEditing`

Fixes #11298. Fixes #10392. Fixes #10532. Fixes #10664. Fixes #10879.
@Splaktar Splaktar added the has: Pull Request A PR has been created to address this issue label Jun 19, 2018
jelbourn pushed a commit that referenced this issue Jun 22, 2018
use jQuery's `contents()` instead of `children()`
since the chip content elements are text nodes
and `children()` doesn't find text nodes
improve double click detection when editable chips are enabled
add/improve JSDoc and types
rename `MdChipCtrl.isEditting` to `MdChipCtrl.isEditing`

Fixes #11298. Fixes #10392. Fixes #10532. Fixes #10664. Fixes #10879.
Splaktar added a commit that referenced this issue Jul 31, 2018
use jQuery's `contents()` instead of `children()`
since the chip content elements are text nodes
and `children()` doesn't find text nodes
improve double click detection when editable chips are enabled
add/improve JSDoc and types
rename `MdChipCtrl.isEditting` to `MdChipCtrl.isEditing`

Fixes #11298. Fixes #10392. Fixes #10532. Fixes #10664. Fixes #10879.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has: Pull Request A PR has been created to address this issue P2: required Issues that must be fixed. resolution: fixed severity: regression This issue is related to a regression type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants