Clicking on the "Select All" option in the angular2-multiselect-dropdown triggers the onDeSelectAll event

I'm facing an issue with angular2-multiselect-dropdown where the "SelectAll" functionality is not working correctly. When I click on "SelectAll", it also triggers the deSelectAll event, causing the onDeSelectAll() function to be called and preventing all items from being selected. The Select All checkbox remains unchecked as well. Can someone please help me figure out how to resolve this before my upcoming deadline?
https://i.sstatic.net/WRI1a.png ts:

  ngOnInit() {
    this.dropdownList = [
      { id: 1, itemName: "Pacemaker1", value: "Pacemaker1" },
      { id: 2, itemName: "Pacemaker2", value: "Pacemaker2" },
      { id: 4, itemName: "Pacemaker2", value: "Pacemaker2" },
    ];

    this.selectedItems = [];

    this.dropdownSettings = {
      singleSelection: false,
      text: "Select devices",
      selectAllText: "Select All",
      unSelectAllText: "UnSelect All",
      enableSearchFilter: true,
      badgeShowLimit: 3,
    };
    this.getStudies();
  }

  onItemSelect(item: any) {
    this.selectedItems.push(item);
  }

  OnItemDeSelect(item: any) {
    this.selectedItems = this.selectedItems.filter((el) => el.id !== item.id);
  }

  onSelectAll(items: any) {
    console.log("select", items);
    this.selectedItems = [];
    this.selectedItems.push(items);
  }

  onDeSelectAll(items: any) {
    console.log("deselect", items);
    this.selectedItems = [];
  }

html:

 <div class="form-group">
    <label class="form-col-form-label">
       Associated Devices
    </label>
    <angular2-multiselect
        class="form-control"
        [data]="dropdownList"
        [settings]="dropdownSettings"
        (onSelect)="onItemSelect($event)"
        (onDeSelect)="OnItemDeSelect($event)"
        (onSelectAll)="onSelectAll($event)"
        (onDeSelectAll)="onDeSelectAll($event)"
        formControlName="associatedDevices">
    </angular2-multiselect>
 </div>

Please check the replicated functionality here https://stackblitz.com/edit/angular-ivy-esame2?file=src%2Fapp%2Fapp.component.html

Answer №1

After installing version @4.6.3, the problem was resolved and everything is running smoothly now. It seems that the issue is a known bug in the package.

Answer №2

I encountered a similar problem which can be resolved using CSS in the following manner

label[for=selectAll] {
  pointer-events:none;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript truthy values referring to numbers

According to the rules outlined below: Falsy: false 0 (zero) '' or "" (empty string) null undefinded NaN (e.g. the result of 1/0) Truthy: Anything else I'm puzzled as to why, in the tests that follow, only the number 1 is considered "tr ...

Combining the power of Vuforia with the capabilities of Three

I'm having difficulty with the integration of three.js and Vuforia, as I have limited knowledge about OpenGl which makes it challenging to troubleshoot. Our team is working on a small AR app where we aim to utilize Vuforia for tracking and recognitio ...

Change the return type of every function within the class while maintaining its generic nature

Looking for a solution to alter the return type of all functions within a class, while also maintaining generics. Consider a MyService class: class CustomPromise<T> extends Promise<T> { customData: string; } interface RespSomething { data ...

Embed a function within a string literal and pass it to another component

Is there a way to pass a function defined in actions to an element? Reducer case 'UPDATE_HEADER': return Object.assign({}, state, { headerChildren: state.headerChildren.concat([action.child]) }); Action.js export const deleteH ...

Encountering a rendering error with Jest while trying to load a functional child component

I encountered an error message stating Error: Uncaught [Error: Child(...): Nothing was returned from render while testing the Parent component. Below are the relevant files that were involved: /components/Page/Children/Child.js import React from "re ...

The mesh in threejs doesn't seem to update properly when changed through the GUI

I have successfully created a line mesh with an elliptical shape to represent an orbit with eccentricity e and semi-major axis a. This mesh is a child of a group named orbitGroup, which also contains other objects. In addition, I have implemented a GUI to ...

Hold off on proceeding until the subscription loop has finished

Is there a way to verify that all results have been successfully pushed to nodesToExpand after running the for loop? The getFilterResult function is being called via an HTTP request in the nodeService service. for(var step in paths) { this.nodeSe ...

D3-cloud creates a beautiful mesh of overlapping words

I am encountering an issue while trying to create a keyword cloud using d3 and d3-cloud. The problem I am facing is that the words in the cloud are overlapping, and I cannot figure out the exact reason behind it. I suspect it might be related to the fontSi ...

What is a more effective approach for managing form data with React's useState hook?

Seeking a more efficient solution to eliminate redundancy in my code. Currently, I am utilizing useState() for managing user data, which results in repetition due to numerous fields. Below is a snippet of my current code: const [lname, setLast] = useState& ...

Using Node.js to execute JavaScript with imported modules via the command line

Having limited experience with running JavaScript from the command line, I am facing a situation where I need to utilize an NPM package for controlling a Panasonic AC unit, which includes a wrapper for their unofficial API. My objective is to create a sim ...

A beginner's guide to integrating three.js into your React projects

I am having trouble integrating three.js into my React application. Despite following the basic sample from the three.js documentation, I am unable to load it on the canvas. Initially, I successfully implemented the sample in a vanilla.js sandbox. However ...

Mastering the art of asynchronous programming with $.getJSON

This is how I am approaching the situation: $.getJSON(url1, function(response1){ if(response1.status == 'success'){ $.getJSON(url2, function(response2){ if(response2.status == 'success') { $.getJSON(url3, functi ...

How to fetch and parse a JSON file in Angular using HTTP request

Looking to access a JSON file within my local project for some basic configuration. Here is the code snippet: myM: any; constructor(private http: Http) { this.http.get('config.json') .map((res: Response) => res.json()) ...

Encountering weathers.map is not a function error while using React.js with OpenWeatherMap integration

Struggling with React.js for a college project and need some help. The error message I keep encountering is: weathers.map not a function I know it's probably something simple, but for the life of me, I can't figure it out! My project structure f ...

Deactivating controls while displaying the loading bar in AngularJS

I'm currently working on a web application using AngularJS. I want to incorporate a loading bar to signify long data load times from the server. To replicate heavy data loads, I am utilizing $timeout to trigger the loadbar when the operation begins a ...

employing express.json() post raw-body

Within my Express application, I am aiming to validate the length of the request body and restrict it irrespective of the content type. Additionally, I wish to parse the body only if the content type is JSON. How can I go about accomplishing this? Curren ...

Is it possible to handle both ajax form submissions and browser post submissions in express.js?

On my website, I have implemented a contact form using express.js (4.0). I am contemplating how to manage the scenario where a user disables JavaScript. If the last part of my routing function looks like this: res.render('contact.jade', { tit ...

Exploring the Yahoo Finance Websocket with Angular

Upon visiting the Yahoo finance website (for example, ), I noticed that the page establishes a WebSocket connection. The URL for this WebSocket is wss://streamer.finance.yahoo.com/ I'm currently working on a small project where I need to retrieve dat ...

Utilizing mapped types in a proxy solution

As I was going through the TS Handbook, I stumbled upon mapped types where there's a code snippet demonstrating how to wrap an object property into a proxy. type Proxy<T> = { get(): T; set(value: T): void; } type Proxify<T> = { ...

What is the best way to determine the position of a letter within a string? (Using Python, JavaScript, Ruby, PHP, etc...)

Although I am familiar with: alphabet = 'abcdefghijklmnopqrstuvwxyz' print alphabet[0] # outputs a print alphabet[25] #outputs z I am curious about the reverse, for instance: alphabet = 'abcdefghijklmnopqrstuvwxyz' 's' = al ...