Guys, md-chips it's a very nice tool! But have there few issues that I got.
I have a DB of items, I'm trying to manage this items with AJAX and md-chips.
I am creating new item in my DB by simply typing on the md-chips filed. That's cool!
I can remove my item from DB with "X" icon that I got from documentation.
But after quick QA I got that I can remove items by "backspace" button, and can't send request to my DB, because there is no trigger..
What can I do?
What trigger are you using to create items in your DB when you enter them into md-chips?
@Axel186 - you could establish a watcher on the md-items collection; but this should only be considered a temporary, crude solution.
@typotter - perhaps we should have some events dispatched for chip add, chip remove, chip active ?
@ThomasBurleson - I think events it's great idea!
If I can call functions on adding/remove chips I can control my requests to DB.
We are working with md-chips and workaround watching the model, but would be great to have this events
adding event for chip-remove is a fair request and should be straightforward to implement.
Instead of watching the collection of chips, I did a little 'trick' :
<md-chips ng-model="searchObj.selectedFilters">
<button md-chip-remove class="md-primary md-chip-remove"
ng-click="$parent.$log($chip)">
<md-icon md-svg-icon="md-close"></md-icon>
</button>
</md-chips>
What do you guys think about it ?
Waiting for the events btw :+1:
We just pushed some events to master last week, you can see the docs here: https://material.angularjs.org/HEAD/#/api/material.components.chips/directive/mdChips
_Small note: the md-on-remove and md-on-select aren't actually required, the docs are wrong and will be fixed shortly._
Documentation can use a bit of detail. For anyone wanting to use this, you can do md-on-remove="myCallback($chip, $index)" .
It would be nice to be able to prevent a chip removal with a falsey expression to md-on-remove. The name of the attribute kind of infers that the remove has already been committed to, though, and the expression is just to acknowledge it happening, not control or prevent it. I don't mind submitting a patch if the api change is welcome.
@ab712 PRs for doc improvements are pretty much always welcome and appreciated.
If you wanted to do a PR for the md-on-remove addition, I would say this: if it's a small addition/change, go ahead and submit a PR, but if it looks like you're having to change a lot or re-work some stuff, then definitely reconnect with us before spending a ton of time on it.
@ab712 Thanks for the clarification about md-on-remove. I was searching for that exactly and it was not obvious from docs.
@eighty4 @topherfangio Did you ever manage to prevent the removal of a chip using md-on-remove? I have a scenario where I need this.
I haven't used this stack in a couple of years unfortunately. The latest demos look really nice, though.
Most helpful comment
It would be nice to be able to prevent a chip removal with a falsey expression to md-on-remove. The name of the attribute kind of infers that the remove has already been committed to, though, and the expression is just to acknowledge it happening, not control or prevent it. I don't mind submitting a patch if the api change is welcome.