Trigger the Angular Dragula DropModel Event exclusively from left to right direction

In my application, I have set up two columns using dragula where I can easily drag and drop elements.

<div class="taskboard-cards" [dragula]='"task-group"' [(dragulaModel)]="format">
    <div class="taskboard-task" *ngFor="let forDoc of format | filter: filterValue">
      <div class="taskboard-task-title">{{forDoc}}</div>
    </div>
</div>

and

<div class="taskboard-cards" [dragula]='"task-group"' [(dragulaModel)]="doclist">
    <div class="taskboard-task" *ngFor="let docL of doclist">
      <div class="taskboard-task-title">{{docL}}</div>
    </div>
</div>

I have successfully implemented an event that allows me to retrieve the correct value in my component constructor.

this.subs.add(this.dragulaService.dropModel("task-group")
  .subscribe(({ el, target, source, sourceModel, targetModel, item }) => {
    console.log('dropModel:');
    console.log(el);
    console.log(source);
    console.log(target);
    console.log(sourceModel);
    console.log(targetModel);
    console.log(item);

    this.updateDoc(this.doc, targetModel);
  })
);

However, my challenge lies in making sure that the dropModel event only triggers when dragging from the first column to the second. I attempted to rename task-group to task-group1 and task-group2 but encountered issues with dragging if [dragula] had a different name.

The arrays format and doclist both contain string values. How can I determine if the event originates from the first task-group?

Answer №1

Wow, I managed to find a solution quickly this time! All you have to do is add an ID to your dragula div element.

<div class="taskboard-cards" [dragula]='"task-group"' id="1" [(dragulaModel)]="format">
    <div class="taskboard-task" *ngFor="let forDoc of format | filter: filterValue">
      <div class="taskboard-task-title">{{forDoc}}</div>
    </div>
  </div>

Then make sure to check it in your event listener:

this.subs.add(this.dragulaService.dropModel("task-group")
  .subscribe(({ el, target, source, sourceModel, targetModel, item }) => {
    console.log('dropModel:');
    console.log(el);
    console.log(source.id); // Verify if this is equal to 1
    console.log(target);
    console.log(sourceModel);
    console.log(targetModel);
    console.log(item);

     this.updateDoc(this.doc, targetModel);
  })
);

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

Ultimate combo: React, TypeScript, and Vite for seamless imports!

Problem The issue I'm facing is related to my React app built with the command yarn create vite. I tried to switch to using absolute imports instead of "../../.." in my files, but unfortunately it doesn't seem to work in my React + Vi ...

Error encountered: No provider found for MatSelect in Angular version 14

I recently upgraded my Angular project from version 8 to the latest one, and now I'm encountering an error with mat-select. Angular Version: 14 Angular Material Version: 14.0.4 ERROR NullInjectorError: R3InjectorError(AppModule)[MatSelect -> ...

Guide on utilizing a module in TypeScript with array syntax

import http from "http"; import https from "https"; const protocol = (options.port === 443 ? "https" : "http"); const req = [protocol].request(options, (res) => { console.log(res.statusCode); }); error TS2339 ...

Typescript's async function failing to execute properly

I'm currently facing an issue with my code and I'm a bit puzzled as to where the problem lies. The console is displaying the correct data for this.allNominations, but it appears that the third for-loop is not being executed at all. As a result, t ...

Unable to load content from Three.js Examples library (Error loading script for "three/examples/jsm/loaders/OBJLoader2")

In my Angular application, I have a simple setup using Three.js. When I try to import the `OBJLoader2` from `three/examples/jsm/loaders/OBJLoader2`, everything works fine except when running it with the `ts_devserver`. The browser console shows an error: G ...

Guide to developing a universal store extension

I've been attempting to create a reactive global $store object using a plugin, but so far I have not been successful in getting it to function as intended. store.ts: import {reactive} from "vue"; export default { install: (app:any, opt ...

Utilize the optional chaining feature when accessing properties that may be optional

I recently encountered an issue in my Typescript project where accessing properties or functions of optional properties did not throw any errors. Here is an example: type Example = { bar?: string[] } const foo: Example = {} // Although no error occu ...

Is it possible to build a Node.js (Express) application using a combination of JavaScript and TypeScript?

Currently, I have a Node.js project (Express REST API) that is written in JavaScript. My team and I have made the decision to gradually rewrite the entire project into TypeScript. Is it possible to do this incrementally, part by part, while still being ab ...

Tips for handling API responses in Angular before making another API call

Apologies for the lack of clarity in my question. I am seeking assistance with a specific issue I am facing. I am currently utilizing Angular 6 for frontend development and a .NET Core API for backend operations, which includes making calls to external AP ...

Transform a standard array of strings into a union string literal in TypeScript

I'm currently developing a module where users can specify a list of "allowable types" to be utilized in other functions. However, I'm encountering challenges implementing this feature effectively with TypeScript: function initializeModule<T ex ...

Choose all the checkboxes that use Knockout JS

Struggling with implementing a "select all" checkbox feature as a Junior developer on a complex project utilizing knockout.Js and Typescript. I can't seem to figure out how to select all existing checkboxes. Here is the HTML: <td> <inp ...

Ways to determine the types of props received by a function when the arguments vary for each scenario?

I have a specialized component that handles the majority of tasks for a specific operation. This component needs to invoke the onSubmit function received through props, depending on the type of the calling component. Below is an example code snippet show ...

Knexfile Doesn't Utilize TypeScript Paths

When attempting to run a migration, I encountered an issue with Knex. My Knexfile is in Typescript and uses path aliases from tsconfig.json. However, Knex is throwing an error stating Cannot find module '@foo-alias/bar-module'. What adjustments d ...

Having trouble converting from JavaScript to TypeScript, encountered an error in the process

Seeking assistance with transitioning JavaScript code to TypeScript. const profiles = [{ name: "kamal", age: "20", designation: "developer", grade: "A", }, { name: "arun", age: "25", designation: "developer", grade: ...

Troubleshooting problem with fullscreen mode in videojs on Ionic 2 due to StatusBar issue

Utilizing a Component to run video js in an ionic application I am seeking for the application to cover the status bar when clicking fullscreen on the video The code functions only when placed in the 'constructor' section, but fails to work w ...

Using spyOn to fake Observable responses - a step-by-step guide

My service is set up to request JSON data through HTTP: export class TodosService { constructor(private http: HttpClient) {} getTodos(): Observable<any> { return this.http.get<any>('https://jsonplaceholder.typicode.com/todos') ...

The delay function in RxJS allows for waiting to return a value until a specific condition is met within a stream and

Currently, I am facing an issue with a method in my application that triggers a server request. This method has access to a stream from the redux-store and needs to execute a callback only when the result of the request is found in the mentioned stream. Th ...

Using Angular Material to link a constant within an HTML file

I have set up my constants in the following way: constants.ts export const Constants = Object.freeze({ ACCEPTED_LEADS_TO_CALL: "Accepted Leads to Call", RECOMMENDED_CALL_LIST: "Recommended Call List" }); This makes it easy to refere ...

Is it possible for me to incorporate a portion of the interface?

Is it possible to partially implement an interface? export interface AuthorizeUser { RQBody: { login: string; password: string; }; RSBody: { authorizationResult: AuthorizationResult; }; }; class AuthorizeUserRQBody implements Authorize ...

AmCharts stacked bar chart - dynamically adjust value visibility (adjust transparency) based on user interaction

I recently utilized amcharts to construct a bar chart. The creation of my stacked bar chart was inspired by this specific example. Currently, I am attempting to modify the alpha (or color) of a box when hovering over another element on my webpage, such as ...