-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(chips): allow to specify a maximum of chips that can be added through user input #6897
Conversation
*/ | ||
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--- Improved.
a97d629
to
f027e63
Compare
We should support ng-messages with custom errors when the limit is reached. (much like input with errors). |
Without ngMessages support, this feature creates more issues than it solves. Removed from the merge-queue until feature is finished. |
2654e3a
to
36dc394
Compare
@ThomasBurleson All done 👍 Would be great if you review again. |
36dc394
to
c30042f
Compare
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review here @ThomasBurleson
The demo is broken and does not work: entire a 4th chip and the error message shows. |
@ThomasBurleson - I was sure everything works (testing etc). Will check it now! |
@ThomasBurleson - Update 😄 - Forgot adding ngMessages as dependency. |
f0c7675
to
b214c37
Compare
@ThomasBurleson - Now fixed! |
|
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 😄 ) |
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 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);
}; |
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. |
|
It is a string... inspect in the dev console. |
b214c37
to
bf4d1e3
Compare
@ThomasBurleson - Sorry wrong approach.. Updated it, added style to the custom ngMessages in the demo? and used your string validation for |
@devversion - you need to thoroughly test each PR before submitting. Otherwise the impacts could be huge. |
…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
bf4d1e3
to
0cd886f
Compare
@@ -409,6 +409,71 @@ describe('<md-chips>', function() { | |||
})); | |||
}); | |||
|
|||
describe('md-max-chips', function() { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
@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. |
…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.
The current behavior on chips limit reaching is that there will happen nothing (no input clear).
Any suggestions for the behavior?
Fixes #6864