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

feat(chips): allow to specify a maximum of chips that can be added through user input #6897

Closed
wants to merge 1 commit into from

Conversation

devversion
Copy link
Member

The current behavior on chips limit reaching is that there will happen nothing (no input clear).
Any suggestions for the behavior?

Fixes #6864

*/
MdChipsCtrl.prototype.appendChip = function(newChip) {
// Don't append the chip if the maxmimum is reached
// Return true, to show that the limit is reached
if (this.items.length >= this.maxChips) return true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can swap the return values, it would make more sense to return false if the chip can't be added, but then I need to return false if the chip is a duplicate too... and in this case it should clear the buffer. (so I think the current solution is the most simple)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- Improved.

@devversion devversion force-pushed the feat/chips-max-limit branch 2 times, most recently from a97d629 to f027e63 Compare January 28, 2016 16:38
@ThomasBurleson ThomasBurleson added this to the 1.0.5 milestone Jan 30, 2016
@ThomasBurleson ThomasBurleson self-assigned this Jan 30, 2016
@ThomasBurleson ThomasBurleson added the pr: merge ready This PR is ready for a caretaker to review label Jan 30, 2016
@ThomasBurleson
Copy link
Contributor

We should support ng-messages with custom errors when the limit is reached. (much like input with errors).

@ThomasBurleson ThomasBurleson added needs: work and removed pr: merge ready This PR is ready for a caretaker to review labels Jan 31, 2016
@ThomasBurleson ThomasBurleson modified the milestones: Backlog, 1.0.5 Jan 31, 2016
@ThomasBurleson
Copy link
Contributor

Without ngMessages support, this feature creates more issues than it solves. Removed from the merge-queue until feature is finished.

@devversion devversion force-pushed the feat/chips-max-limit branch 3 times, most recently from 2654e3a to 36dc394 Compare January 31, 2016 17:49
@devversion
Copy link
Member Author

@ThomasBurleson All done 👍 Would be great if you review again.

@devversion devversion force-pushed the feat/chips-max-limit branch from 36dc394 to c30042f Compare January 31, 2016 18:06
@@ -67,6 +67,9 @@
* displayed when there is at least on item in the list
* @param {boolean=} readonly Disables list manipulation (deleting or adding list items), hiding
* the input and delete buttons
* @param {number=} md-max-chips The maximum number of chips allowed to add through user input.
* <br/><br/>The validation property `md-max-chips` can be used when the max chips
* amount is reached.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review here @ThomasBurleson

@ThomasBurleson ThomasBurleson added pr: merge ready This PR is ready for a caretaker to review and removed needs: work labels Feb 4, 2016
@ThomasBurleson ThomasBurleson modified the milestones: 1.0.5, Backlog Feb 4, 2016
@ThomasBurleson
Copy link
Contributor

The demo is broken and does not work: entire a 4th chip and the error message shows.
@devversion - did you test this ?

@ThomasBurleson ThomasBurleson added needs: work and removed pr: merge ready This PR is ready for a caretaker to review labels Feb 4, 2016
@devversion
Copy link
Member Author

@ThomasBurleson - I was sure everything works (testing etc). Will check it now!

@devversion
Copy link
Member Author

@ThomasBurleson - Update 😄 - Forgot adding ngMessages as dependency.

@devversion devversion force-pushed the feat/chips-max-limit branch from f0c7675 to b214c37 Compare February 4, 2016 16:00
@devversion
Copy link
Member Author

@ThomasBurleson - Now fixed!

@ThomasBurleson
Copy link
Contributor

@devversion:

  • what about the error text color?
  • Is the error message too close to the chip bottom border?

@devversion
Copy link
Member Author

I don't know, I thought I should just add ngMessages support - but I can create a custom styling just for the styling? Support for ngMessages for the complete chips will be another issue / PR, (would like to that, if needed 😄 )

@ThomasBurleson
Copy link
Contributor

Also this logic appears wrong:

MdChipsCtrl.prototype.validateModel = function() {
  var isMaximumReached = !(this.maxChips && this.items.length >= this.maxChips);
  this.ngModelCtrl.$setValidity('md-max-chips', isMaximumReached);
};

And this.items.length is a number while this.maxChips is === "5".

Please use this code:

MdChipsCtrl.prototype.hasMaxChips = function() {
  this.maxChips = (angular.isString(this.maxChips) ) ? parseInt(this.maxChips,10) || 0 :
                  (angular.isUndefined(this.maxChips) ) ? 0 : this.maxChips;

  return (this.maxChips > 0) && (this.items.length >= this.maxChips);
};

@ThomasBurleson
Copy link
Contributor

full Support for ngMessages is overkill for this PR. Yet if we use ngMessages to show an error, then that message should be colored accordingly IMO.

@devversion
Copy link
Member Author

this.maxChips won't be a string, it will be interpolated from the scope, so it will be an integer? Or you mean, when the user specifies a string? (like md-max-chips="hello 1")?

@ThomasBurleson
Copy link
Contributor

It is a string... inspect in the dev console.

@devversion devversion force-pushed the feat/chips-max-limit branch from b214c37 to bf4d1e3 Compare February 4, 2016 16:32
@devversion
Copy link
Member Author

@ThomasBurleson - Sorry wrong approach.. Updated it, added style to the custom ngMessages in the demo? and used your string validation for maxChips - (working on the CI)

@ThomasBurleson
Copy link
Contributor

@devversion - you need to thoroughly test each PR before submitting. Otherwise the impacts could be huge.

@ThomasBurleson ThomasBurleson added pr: merge ready This PR is ready for a caretaker to review and removed needs: work labels Feb 4, 2016
…rough user input

The current behavior, when the limit is reached, that there will happen nothing (no input clear).
But this behavior should be tested for the UX

Fixes angular#6864
@devversion devversion force-pushed the feat/chips-max-limit branch from bf4d1e3 to 0cd886f Compare February 4, 2016 16:44
@@ -409,6 +409,71 @@ describe('<md-chips>', function() {
}));
});

describe('md-max-chips', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devversion - are these passing for you ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now Passing (just said in the comment before 😄, so please don't be to harsh).

Updated the check to ->

MdChipsCtrl.prototype.hasMaxChips = function() {
  if (angular.isString(this.maxChips)) this.maxChips = parseInt(this.maxChips, 10) || 0;

  return this.maxChips > 0 && this.items.length >= this.maxChips;
};

If undefined the it will return false, because undefined > 0 will be false.

@devversion
Copy link
Member Author

@ThomasBurleson - Yes, next time I will test it more thoroughly. Just wasn't sure about ngMessages, but in my case everything worked perfect until the ngMessages support was requested. So next time I will check more thoroughly when updating a PR.

ErinCoughlan pushed a commit to ErinCoughlan/material that referenced this pull request Feb 9, 2016
…dded through user input

Current UX provides no indication of when max chips has been reached.

* use ngMessages to show information at max limit condition.

Fixes angular#6864. Closes angular#6897.
ThomasBurleson pushed a commit that referenced this pull request Apr 1, 2016
…dded through user input

Current UX provides no indication of when max chips has been reached.

* use ngMessages to show information at max limit condition.

Fixes #6864. Closes #6897.

# Conflicts:
#	src/components/chips/chips.spec.js
#	src/components/chips/js/chipsController.js
@devversion devversion deleted the feat/chips-max-limit branch April 21, 2016 12:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr: merge ready This PR is ready for a caretaker to review type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants