Separator after x elements in a react-beautiful-dnd list

I’m trying to have a separator between my 3rd and 4th element in a react-beautiful-dnd <Droppable/>.

It’s pretty easy to have it before drag, after drag, the problem is when it comes to have it during drag. For example, if I drag my fourth element into 2nd place, I want to have these steps :

1 2 3 | 4 5
     << 4
1 2 3 | □  5
 << 4
1 2 □ | 3 5
  4
1 □ 2 | 3 5
1 4 2 | 3 5

while I drag my 4th element over.

For now, I’m using CSS to create the separator (border-bottom on li:nth-child(3)), I’d like to keep it this way if possible. One of the problem is that react-beautiful-dnd does not move html elements up and down the list, it transforms them using css translate(x,y), which is hard to track to know which elements are the 3rd and 4th at any point.

Is there any way to know an element has moved up/down the list using css ? Or to add a specific class when an element is being moved (moved by the api, not by the user dragging) ?

Also, using 2 lists with automated swapping seems complex for that kind of problem, but I might just have to go for it…

If anyone has an idea on how to achieve this, I’ll be very grateful 🙂

Cheers

Can not click() on Selenium

Code on the IDE

I am trying to click a checkbox and I am not able to do it.


try {
WebElement primaryParticipant = driver.findElement(By.xpath("//*[@id="searchable-list-input-primaryParticipantSearchable"]"));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
WebElement other = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//li[5]/mat-checkbox[@class="mat-checkbox chp-ds pt-75 mat-primary ng-untouched ng-pristine ng-valid"]")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", other);
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", primaryParticipant); //Scroll into the Additional Participants Section
captureImage();
Thread.sleep(2000);
WebElement participantText = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class="mat-form-field-infix ng-tns-c14-7"]/textarea")));
participantText.click();
Thread.sleep(2000);
participantText.sendKeys("Automation Test");
Thread.sleep(2000);
captureImage();
} catch (Exception e) {
captureImage();
throw new AssertionError("Could not select Other on the checkbox or write on it.", e);
}

Right now I am trying to do the click() with Javascript because I found the error related to org.openqa.selenium.ElementClickInterceptedException: element click intercepted:

So I am trying with Javascript. When I try to do the click with Javascript the element is not being clicked and I am getting an error of the next variable participantText that it is not visible. This is because the checkbox of Other was not clicked and the TextArea is not visible.

How can I click on Other?

What is the best way to use dataLayer custom variable in Google tag manager for sales tracking in google ads

My gtm script is already setup. and dataLayer push is also working fine.

But cant able to get value of transcationId, currency & transcationTotal in google tag manager on order completed page of our website

I have tried via javascript, html hidden field id & custom javascript as well but never worked.

My dataLayer variable is defined like this:

enter image description here

Here is dataLayer array with values in console on order completed page:

enter image description here

Getting result like this:
enter image description here

I have tried so many ways like:

  • dataLayer.currency
  • dataLayer[0].currency
  • currency
  • window.dataLayer[0].currency
  • etc

but no luck 🙁

Module not found: Error: Can’t resolve ‘@babel/runtime/helpers/createClass’

I am importing an external package into a CyberChef custom operation. I am not sure how I should import the package. The package is not published but is link using a file:./... dependency.

From CyberChef

MyOperation.mjs

import SystemDatabase from "test-db";

My external package

package.json

{
    "name": "test-db",
    ...
    "main": "src/main.js",
    ...
}

main.js

import SystemDatabase from "./SystemDatabase.js";

module.exports = {
    SystemDatabase
};

SystemDatabase.js

class SystemDatabase {
// ...
}

module.exports = {
    SystemDatabase
};

Build error

This is the error I don’t understand.

ERROR in ../[REDACTED]/test-db/src/SystemDatabase.js 2:0-62
    Module not found: Error: Can't resolve '@babel/runtime/helpers/createClass' in '[REDACTED]/test-db/src'
    resolve '@babel/runtime/helpers/createClass' in '[REDACTED]/test-db/src'
      Parsed request is a module
      using description file: [REDACTED]/test-db/package.json (relative path: ./src)


        Field 'browser' doesn't contain a valid alias configuration
        resolve as module
          [REDACTED]/test-db/src/node_modules doesn't exist or is not a directory
          [REDACTED]/test-db/node_modules doesn't exist or is not a directory
          [REACTED]/node_modules doesn't exist or is not a directory
          ...
     @ ../[REACTED]/test-db/src/main.js 2:0-47 4:2-15
     @ ./src/core/operations/MyOperation.mjs 15:0-44
     @ ./src/core/config/modules/MyModule.mjs 12:0-69 22:18-34

Follow-up

After installing babel-runtime to my external package. I now get the runtime error:

ES Modules may not assign module.exports or exports.*, Use ESM export syntax

If I use export default syntax, I get :

SyntaxError: Cannot use import statement outside a module

I want my package to import in all JS project types.

Can someone explain the issue on adding to NextJs14?

While creating NextJs project, I tried to integrate Vercel Speed Insight

import { SpeedInsights } from "@vercel/speed-insights/next" 
<SpeedInsights />

It returns some hydration error.
Can someone explain and how can I fix this?

here are some screenshots
enter image description here

if I comment this tag, the errors are resolved

Chart.js: Is there a way to have a chart with fixed height and variable width based on the number legend’s items

I would like to know if there is a way to make the chart’s width increase if the number of items in the legend doesn’t fit with its initial size

I tried a lot of different settings and approces like changing style attributes on container but none of them could solve my problem.

I use Chart.js v3.8.1
I prepared a codepen to help me explain the request:
Codepen

<div class="container">
    <div class="chart-container">
        <canvas style="height: 300px; width: 100%"></canvas>
    </div>
</div>
.container {
    width: 100%;
    height: 400px;
    border: 3px solid red;
    display: flex;
}

.chart-container {
    border: 2px solid blue;
    width: fit-content;
    margin: auto 0;
    width: fit-content;
}

canvas {
    border: 2px solid green;
}

$(document).ready(() => {
    let preparedData = prepareData(60);
    const config = {
        type: "doughnut",
        data: preparedData,
        options: {
            responsive: false,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: true,
                    position: "right"
                }
            }
        }
    };

    let chart = new Chart($("canvas"), config);
});

function prepareData(numData) {
    let labels = [];
    let localData = [];

    for (idx = 0; idx < numData; idx++) {
        labels.push("Data " + idx);
        let random = getRandomInt(100);
        localData.push(random);
    }

    let datasets = [
        {
            label: "Info",
            data: localData,
            borderWidth: 0
        }
    ];

    return { labels, datasets };
}

function getRandomInt(max) {
    return Math.floor(Math.random() * max);
}

Class added by javascript but css not applied? [closed]

I am going to create a toggle menu using javascript and css
A class .menu-slider add with property display blok. But it’s not working only class teggled and css not applied
Here is the code

<script>
    const toggleMenu = document.querySelector('.toggl-menu');
    document.getElementById("toggleButton").addEventListener("click", function() {
        var button = this;
        toggleMenu.classList.toggle('menu-slider');
        button.classList.toggle("open");
        button.classList.toggle("close");
        var openIcon = button.querySelector(".open-icon");
        var closeIcon = button.querySelector(".close-icon");
        if (button.classList.contains("open")) {
            openIcon.style.display = "inline";
            closeIcon.style.display = "none";
        } else {
            openIcon.style.display = "none";
            closeIcon.style.display = "inline";
        }
    });
</script>

<style>
    .toggl-menu {
        display: none;
        position: absolute;
        padding-top: 1rem;
        padding-bottom: 1rem;
        align-items: center;
        border-bottom-right-radius: 1rem;
        border-bottom-left-radius: 1rem;
        width: 100%;
        background-color: #ffffff;
        left: 0;    
        top: 70px;
    }
    .menu-slier{
        display: block;
        transition-duration: 500ms;
    }
</style>

Video (HTMLMediaElement) duration property does not return full length of video

I would like to display the total duration of a video in a <video> HTML Media element. The only way to get this as far I can see is by using the duration property:

HTML

<video src="/videos/test.mp4">This is a 47 second video</video>

Script

  const video = document.querySelector("video");
    
    video.addEventListener("loadedmetadata", ()=>{
      console.log(video.duration); // returns only 5 seconds
    });
    
    video.addEventListener("loadeddata", ()=>{
      console.log(video.duration); // returns only 5 seconds
    });
    
    video.addEventListener("durationchange", ()=>{
      console.log(video.duration); // increases as video starts plays
    });

However, the duration will only show 0:05 when the page loads (using a formatTime() function not shown in code above).

The HTMLMediaElement spec says duration is “A read-only double-precision floating-point value indicating the total duration of the media in seconds”. https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration

The time only starts updating when the user clicks on play, and increases like this:

0:05
0:06
...
0:34
0:37
...
0:42
0:47

Cleary video.duration is only returning the first 5 seconds that has been loaded and then starts increasing as more data is loaded. Why does it not return the total length of the video as its supposed to from the metadata?

This causes more problems than just showing the correct total duration. The video playhead keeps skipping back each time more data is loaded because it doesn’t know how long the video will be until starts playing/loading.

Any suggestions on what’s going on?

Javascript – json, denormalize array of object

I have a json object made like this (array of object with array element)

var orders = [
  {
    "employ": {
      "id": "1",
      "name": "1_name",
    },
    "order": [
      {
        "number": "1_1",
        "desc": "1_1_desc"
      },
      {
        "number": "1_2",
        "desc": "1_2_desc"
      }      
    ]
  },
  {
    "employ": {
      "id": "2",
      "name": "2_name",
    },
    "order": [
      {
        "number": "2_1",
        "desc": "2_1_desc"
      }      
    ]
  }  
]

and I have to denormalize it to get this, a simple array of objects

[
  {
    "emp_id": "1",
    "emp_name": "1_name",
    "ord_number": "1_1",
    "ord_desc": "1_1_desc"
  },
  {
    "emp_id": "1",
    "emp_name": "1_name",
    "ord_number": "1_2",
    "ord_desc": "1_2_desc"
  },
  {
    "emp_id": "2",
    "emp_name": "2_name",
    "ord_number": "2_1",
    "ord_desc": "2_1_desc"
  }
]

I use two nested for, but I was wondering if it is possible to do it in another way, perhaps more performing.

var orders_flat = [];
for(var i = 0; i < orders.length; i++) {
  for(var a = 0; a < orders[i].order.length; a++) {
    var o = {};
    o.emp_id     = orders[i].employ.id;
    o.emp_name   = orders[i].employ.name;
    o.ord_number = orders[i].order[a].number;
    o.ord_desc   = orders[i].order[a].desc;
    orders_flat.push(o);
  }
}

TIA

Nested div elemment onclick calls all div’s click event

I have html code as bellow;

<div onclick=alert("First div")>
    <div onclick=alert("Second div")>
        <div onclick=alert("Third div")>
        </div>
    </div>
</div>

The problem is when inner most div is clicked all three alert message displayed.

How can I modify the code so that only 1 alert message will display corresponding to div tag.

Button not respecting height of parent div

The first button isn’t respecting the height of the div that’s surrounding it, causing the image to poke out of the div.

<div class="bg-card text-card-foreground overflow-hidden rounded-xl border shadow-sm animate-fade-in h-[330px] w-64">
  <div class="flex items-center justify-center gap-2 h-36 p-0"><button class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 text-foreground underline-offset-4 hover:opacity-90"><img src="https://placehold.co/700" class="h-full w-full object-cover"></button></div>
  <div class="flex items-center p-6 flex-col gap-2"><button class="inline-flex items-center justify-center whitespace-nowrap rounded-md font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 text-foreground underline-offset-4 hover:opacity-90 text-lg">Title</button>
    <p>Subtitle</p>
    <p class="line-clamp-3 text-center text-sm">This is a description</p>
  </div>
</div>

enter image description here

Codepen

If you remove the first button, the image respects the height of the surrounding div:

enter image description here

Codepen

What’s in a button tag that causes this?

Vue.js Version finding program only returns a white screen

I did write a program to simply display the vue version. Not only i dont get the alert but all I get is a white screen. Im a beginner on javascript and I had installed latest version of nodejs and done programs on it. now I installed vue exactly how the vuejs site has told and it didnt seem to work. I cant find my mistake either but when i try the version of vue on cmd it shows the version correctly

this is my pgm. console log says Vue is not defined.

<html>
 <head>
 <meta charset="utf-8" />
 <script src="https://unpkg.com/vue@next"></script>
 </head>
 <body>
 </body>
 
 <script>
 alert(`Vue.version = ${Vue.version}`);
  </script>
</html>

but when i try it on cmd using
vue --version
i get the correct version