Skip to content

Commit

Permalink
Merge pull request #12516 from primefaces/issue-12460
Browse files Browse the repository at this point in the history
Fixed #12460 - MultiSelect: Add event onRemove
  • Loading branch information
cetincakiroglu committed Jan 18, 2023
2 parents fb5f6c7 + 48471a5 commit fb02073
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export interface MultiSelectFilterOptions {
reset?: () => void;
}

export interface MultiselectOnRemoveEvent {
newValue: object;
removed: MultiSelectItem;
}

@Component({
selector: 'p-multiSelectItem',
template: `
Expand Down Expand Up @@ -444,6 +449,8 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft

@Output() onLazyLoad: EventEmitter<any> = new EventEmitter();

@Output() onRemove: EventEmitter<MultiselectOnRemoveEvent> = new EventEmitter();

/* @deprecated */
_autoZIndex: boolean;
@Input() get autoZIndex(): boolean {
Expand Down Expand Up @@ -724,6 +731,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
let selectionIndex = this.findSelectionIndex(optionValue);
if (selectionIndex != -1) {
this.value = this.value.filter((val, i) => i != selectionIndex);
this.onRemove.emit({ newValue: this.value, removed: optionValue });

if (this.selectionLimit) {
this.maxSelectionLimitReached = false;
Expand Down
5 changes: 5 additions & 0 deletions src/app/showcase/components/multiselect/multiselectdemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ <h5>Events</h5>
</td>
<td>Callback to invoke in lazy mode to load new data.</td>
</tr>
<tr>
<td>onRemove</td>
<td>event: MultiselectOnRemoveEvent</td>
<td>Callback to invoke in lazy mode to load new data.</td>
</tr>
</tbody>
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/showcase/components/multiselect/multiselectdemo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { CountryService } from '../../service/countryservice';
import { SelectItemGroup } from 'primeng/api';
import { CountryService } from '../../service/countryservice';

interface City {
name: string;
Expand Down

0 comments on commit fb02073

Please sign in to comment.