jQuery How to get Ids and other data from a table row?

I’m working with a form that includes dynamic rows in a table,
and I want to extract the selector IDs and textboxs data from the rows in the table.
I want to collect the IDs of the HTML elements within each row.

You can find javascript below:

var strHiddenTableData = "";
    function StrHiddenTableData(tableId) {
        strHiddenTableData = "";
        $('#orderDetails tr').each(function () {
            var row = $(this);
            row.find("input").each(function () {
                strHiddenTableData += $(this).val() + ",";
            });
            strHiddenTableData += "|";
        });
        if (strHiddenTableData.endsWith("|")) {
            strHiddenTableData = strHiddenTableData.slice(0, -1);
        }
        jQuery('#hiddenTableData').val(strHiddenTableData);
    }

Regards

I expected to learn here.

$gte and $lte not working with node.js/mongoose

I am simply trying to count some documents. When using other parameters such as “type”: “someType”, I get the correct count. But when I use {"createdAt": {"$gte": "", "$lte": ""}} (with actual dates which are JS date objects) I get 0 as the count. Been at this for days now, and I can’t seems to find the solution…

I tried narrowing the case down to the smallest reproducable possible. Like so:

  const query = {
    createdAt: {"$gte": new Date("2023-11-01"), "$lte": new Date("2023-11-30")},
  }

const result = await Entity.countDocuments(query)

This returns 0, even though I know for 100% that I have documents matching the critera, with e.g. “createdAt”: ‘2023-11-06T08:09:07.000Z’.

Trying the same countDocuments() function with other parameters returns correct number, for instance:

  const query = {
    tags: {"$nin":["false-positive", "out-of-scope"]},
  }

const result = await Entity.countDocuments(query)

The above will return the correct number of documents which does not have these two strings in its “tags”-field.

I have also tried using the “$and” operator, like so:

  const testQuery = {
    $and: [{ createdAt: { $gte: new Date("2023-10-01") } }, { createdAt: { $lte: new Date("2023-11-31") } }],
  }

But with no luck.

I have also tried logging out the query with the operators, and pasting it into MongoExpress “Advanced”-tab. This returns the correct documents, so the issue seems to be with Mongoose or Node.js.

I have no idea why it is not working with the “$gte” and “$lte”, please help.

Problem with auto open tabs and do something and the close them with javascript

I have written a code which should work fine but i cant seem to find whats the problem, each part of the code works just fine individually, but not as a whole..
here is the code:

async function main() {
    // Get all div elements with the class "product-list" in products pages
    var cursorPointerDivs = document.getElementsByClassName('product-list');

    // Iterate through the div elements with the class "cursor-pointer"
    for (var i = 0; i < cursorPointerDivs.length; i++) {
        await new Promise((resolve) => {
            setTimeout(async function () {
                var currentDiv = cursorPointerDivs[i];
                // Check if the div has a child with class "block cursor-pointer"
                var aChild = currentDiv.querySelector('a.block.cursor-pointer');
                if (aChild && aChild.href != null) {
                    // Print the src attribute of the img child
                    console.log('Found source:', aChild.href);
                    await dothejob(aChild.href, 1, i + 1);
                }
                resolve(); // Resolve the promise after the timeout
            }, 2500);
        });
    }
}

async function dothejob(pUrl, pgindex, prindex) {
    return new Promise((resolve) => {
        var linkUrl = pUrl;

        // Open a new tab and navigate to the specified URL
        var newTab = window.open(linkUrl, '_blank');

        // Wait for a specified duration (e.g., 3000 milliseconds or 3 seconds)
        setTimeout(async () => {
            // Access the content of the new tab
            var newTabDocument = newTab.document;

            // Get all div elements with the class "cursor-pointer"
            var cursorPointerDivs = newTabDocument.getElementsByClassName('cursor-pointer');

            // Iterate through the div elements with the class "cursor-pointer"
            for (var ii = 0; ii < cursorPointerDivs.length; ii++) {
                var currentDiv = cursorPointerDivs[ii];
                // Check if the div has an img child with class "w-full inline-block"
                var imgChild = currentDiv.querySelector('img.w-full.inline-block');
                if (imgChild && !imgChild.closest('picture') && imgChild.src.includes('statics-public')) {
                    // Print the src attribute of the img child
                    console.log('Image source:', imgChild.src);

                    // Resolve the promise
                    resolve();
                    return; // Exit the loop after finding the first match
                }
            }

            // Close the new tab
            newTab.close();

            // Resolve the promise even if no match was found
            resolve();
        }, 3000); // Adjust the delay as needed
    });
}

// Call the main function
main();

the point is getting an image from each item from one page of items, open 10 at the same time and do the process, but this doesnt work or with a few teaks just does the first items and then stops while saying promise in console of the browser.

Im executing this code in the console windows of browser.

Thank you all.

Safari datetime-local form validity bug after unsetting value

Using the following form in Safari, if you set a date and then use the “clear” button to unset it, Safari will invalidate the form even though it’s valid.

It also doesn’t assign the input element with a validationMessage. Removing novalidate, all it does is select the day part of the input.

Am I missing something or is this a Safari bug? The form validates fine in Chrome.

https://jsfiddle.net/n_cholas/zfo9qm6p/27/

<form novalidate>
  <input type="datetime-local">
  <button type="button">clear</button>
  <button>Submit</button>
</form>

<script>
const form = document.getElementsByTagName('form')[0]
const input = document.getElementsByTagName('input')[0]
const btn = document.getElementsByTagName('button')[0]

btn.addEventListener('click', function(e) {
  input.value = ''
})

form.addEventListener('submit', function(e) {
  e.preventDefault();
  
  console.log('checkValidity', form.checkValidity())
  console.log('validationMessage', input.validationMessage)
})
</script>

Tab focus from iframe to iframe of different inputs Javascript

I’m facing this issue for jumping between inputs using Tab key,
this iframe is loaded by third party payment gateway and each input is a different iframe in itself so whenever we try to press tab in any input it just does nothing (since inputs are inserted dynamically after page load), I have tried tabindex, jquery, javascript events, iframe related functions but nothing is working and whenever I try to access the input using this cmd “contentWindow.document” it gives cross origin frame error since js is loaded by third party.
please suggest me with some solution.

iframe Input boxes

I have tried tabindex, jquery, javascript events, iframe related functions but nothing is working and whenever I try to access the input using this cmd “contentWindow.document” it gives cross origin frame error since js is loaded by third party. Only “change”, “blur”, and “focus” events are available directly for inputs by external js.

Problem CesiumJS left double click camera [closed]

I’m adding to Entity Wall and Polyline. I also specify Model in the properties of the Entity. I have checkboxes that enable and disable Wall and Polyline. When they are enabled, when you double-click on an Entity, the camera points to the center of the Wall or Polyline. I need the camera to capture the Entity when double clicking on the Entity. What could be the reason?

I tried to find some property, but there is no such thing. Has anyone encountered this problem?

how can i force a rerender of the map in azuremaps?

I’m trying to make a search function for my indoor azuremaps project, I can search throught the loaded geojson shapes based on name. Now when I highlight, or click on a search result I want it to show the corresponding room in a different color, to do this I made a switch case statement in the data driven styling of the layer, but when I change the corresponding property nothing happens. I assume I have to rerender the map.

//Add a layer for rendering the outline of polygons.
        var polygonExtrusionLayer = new atlas.layer.PolygonExtrusionLayer(datasource, null, {
            height: ['*', ['+', 1, ['to-number', ['get', 'Bouwlaag']]], floorheight],
            base: ['*', ['to-number', ['get', 'Bouwlaag']], floorheight],
            fillOpacity: 0.8,
            fillColor: ['case',
                ['<', ['to-number', ['get', 'Bouwlaag']], currentFloor],
                'lightblue',
                ['case',
                    ['==', ['get', 'resultId'], resultId],
                    'red',
                    'blue'
                ]
            ],
            filter:
                ['all',
                    ['any',
                        ['==', ['geometry-type'], 'Polygon'],       //Only render Polygon or MultiPolygon in this layer.
                        ['==', ['geometry-type'], 'MultiPolygon']
                    ],
                    ['<=', ['to-number', ['get', 'Bouwlaag']], currentFloor]
                ]
        });
function featureClicked(id) {
    var shape = datasource.getShapeById(id);
    console.log(id)
    resultId = id;
    currentFloor = Number(shape.getProperties().Bouwlaag);
    shape.addProperty('resultId', id);
}

I searched online and in this article(text it says that the map canvas is refreshed when I call the addProperty feature of a shape, but when I do so nothing happens. I have a similar question when updating the floor I’m looking at, nothing changes, do I have to keep creating and removing layers, or am I missing something that will allow me to for a refresh/rerender of the map?

Using Vite to bundle assets in a laravel package

I am building a laravel package that exposes a user interface (kinda like telescope and horizon do).

I am trying to use vite but bundling and publishing the assets is proving to be quite a challenge.

My package is setup under a packages/rascan/hela folder inside a default laravel application.

I have published assets and loaded views from within my package’s service provider

$this->loadViewsFrom(__DIR__.'/../resources/views', 'rascan');

$this->publishes([
    __DIR__.'/../public' => public_path('vendor/hela'),
], 'hela'); 

I am then using the @vite directive to include the necessary files in my blade file (inside the package)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    @vite('resources/js/app.js', 'vendor/hela/build')
</head>
<body>
    <div id="app">
        <example-component></example-component>
    </div>
</body>
</html>

I have a vue component (ExampleComponent.vue) that I am trying to access from the blade file but nothing happens when I visit the browser. I just end up with a blank page – visiting it from the top level laravel app.

This is my app.js

import { createApp } from 'vue'
import ExampleComponent from './components/ExampleComponent.vue'

alert("ddsfsdfs")

createApp({
    components: {
        ExampleComponent,
    }
}).mount('#app')

This is my package’s vite.config.js

import { defineConfig } from 'vite'
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [
    laravel([
        'resources/js/app.js'
    ]),

    vue({
      template: {
        transformAssetUrls: {
          base: null,
          includeAbsolute: false,
        },
      },
    })
  ],
})

I would love to watch for changes that I make from inside my package or just build them and access them from the parent laravel application. I tried to find examples even from laravel’s ecosystem but seems they (horizon, telescope etc) are still using laravel mix.

How can I hide/show certain rows from my table with javascript

I need to dynamically hide/show table rows from this table. How can I do that with javascript? I can’t seem to figure it out.

PS, using the data-id isn’t possible.

<div class="view-grid">
  <span aria-label="Kies één record en klik op Selecteren om door te gaan" tabindex="0">
    Kies één record en klik op Selecteren om door te gaan
  </span>
  <table aria-relevant="additions" role="grid" class="table table-fluid table-hover">
    <thead>
      <tr>
        <th scope="col" aria-readonly="true" style="width:5.141388174807198%;" class="sort-disabled" aria-label="Selecteren" data-th="<span class='fa fa-check' aria-hidden='true'></span> <span class='sr-only'>Selecteren</span>">
          <span class="fa fa-check" aria-hidden="true"></span> 
          <span class="sr-only">Selecteren</span>
        </th>
        <th scope="col" aria-readonly="true" style="width:17.737789203084834%;" class="sort-enabled">
          <a href="#" role="button" aria-label="Name" tabindex="0">
            Name<span class="sr-only sort-hint">. aflopend sorteren</span>
          </a>
        </th>
        <th scope="col" aria-readonly="true" style="width:77.12082262210797%;" class="sort-enabled">
          <a href="#" role="button" aria-label="Omschrijving" tabindex="0">
            Omschrijving<span class="sr-only sort-hint">. aflopend sorteren</span>
          </a>
        </th>
      </tr>
    </thead>
    <tbody style="">
      <tr data-id="7b9cf41e-1189-ee11-8179-000d3adf6334" data-entity="ccp_vrijstellingcode" data-name="A2"></tr>
      <tr data-id="52689d1e-1189-ee11-8179-0022489a0604" data-entity="ccp_vrijstellingcode" data-name="A5"></tr>
      <tr data-id="0bd31822-1189-ee11-8179-0022489f9d46" data-entity="ccp_vrijstellingcode" data-name="X2"></tr>
    </tbody>
  </table>
</div>

I have tried to use the getElementsByClassName()

Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. While building a chrome extension

The goal of this Chrome extension is to enable users to capture screenshots of a selected area within the browser just like this extension (https://chrome.google.com/webstore/detail/edlifbnjlicfpckhgjhflgkeeibhhcii). Below is the code for the extension, including the manifest file, popup HTML, popup JavaScript, content script, and background script.

//manifest.json

{
  "manifest_version": 3,
  "name": "My Extension",
  "version": "1.0.1",
  "permissions": ["activeTab", "storage", "tabs"],

  "background": {
    "service_worker": "background.js"
  },

  "action": {
    "default_popup": "popup.html"
  },

  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["contentScript.js"]
    }
  ]
}

popup.html

<!DOCTYPE html>
<html>
  <head>
    <title>My Extension</title>
    <script src="./jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <button id="btn">Start Selection</button>
    <script src="popup.js"></script>
  </body>
</html>

popup.js

document.getElementById("btn").addEventListener("click", function () {
  console.log(chrome);
  chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
    chrome.tabs.sendMessage(tabs[0].id, { action: "startSelection" });
  });
});

contentScript.js

// contentScript.js
var start = {};
var end = {};
var isSelecting = false;

$(window).on("mousedown", function (event) {
  isSelecting = true;
  start.x = event.pageX;
  start.y = event.pageY;

  $("#selection").removeClass("complete");
  $("#start").text("(" + start.x + "," + start.y + ")");
  $("#selection").css({
    left: start.x,
    top: start.y,
  });
});

$(window).on("mousemove", function (event) {
  if (!isSelecting) {
    return;
  }

  end.x = event.pageX;
  end.y = event.pageY;

  $("#selection").css({
    left: start.x < end.x ? start.x : end.x,
    top: start.y < end.y ? start.y : end.y,
    width: Math.abs(start.x - end.x),
    height: Math.abs(start.y - end.y),
  });
});

$(window).on("mouseup", function (event) {
  isSelecting = false;
  $("#selection").addClass("complete");
  $("#end").text("(" + end.x + "," + end.y + ")");

  chrome.runtime.sendMessage({
    action: "sendSnapshot",
    start: start,
    end: end,
  });
});

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  if (request.action === "blurTab") {
    $("body").css("filter", "blur(5px)");
  }
  if (request.action === "unblurTab") {
    $("body").css("filter", "none");
  }
});

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  if (request.action === "startSelection") {
    chrome.runtime.sendMessage({ action: "blurTab" });
  }
});

background.js

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  if (request.action === "sendSnapshot") {
    chrome.tabs.captureVisibleTab({ format: "png" }, function (dataUrl) {
      // Extract the selected area from the snapshot
      const canvas = document.createElement("canvas");
      const ctx = canvas.getContext("2d");
      const img = new Image();
      img.onload = function () {
        canvas.width = Math.abs(request.start.x - request.end.x);
        canvas.height = Math.abs(request.start.y - request.end.y);
        ctx.drawImage(
          img,
          request.start.x,
          request.start.y,
          canvas.width,
          canvas.height,
          0,
          0,
          canvas.width,
          canvas.height
        );
        const snapshotUrl = canvas.toDataURL("image/png");

        // Do something with the snapshot URL, for example, send it to the server
        console.log(snapshotUrl);

        // Unblur the tab
        chrome.tabs.sendMessage(sender.tab.id, { action: "unblurTab" });
      };
      img.src = dataUrl;
    });
  }
}
);

I don’t even know what is causing the problem

Synchronization problem in my multiplayer card game [closed]

I have a single/multi player card game. I have a synchronisation problem in multiplayer. When I click on cards nothing changes in player 2 and player 1 and player 2 don’t have the same card table.

For example player 1 has a fox on card 1 and player 2 has a lion on card 1. Separately I want player 1 to click on 2 cards and after matching I want player 2 to take his turn but I couldn’t do that either, can you help me, thanks.

1. Player Screen
2. Player Screen

I wrote a code that asks us to enter the room name when Multiplayer is clicked so that I can gather 2 players in a room. When both players enter the room, the card table screen comes up in 3.5 seconds and the game starts, but as I said, I couldn’t synchronize. I tried to give socket.id to both users because the cardOpened information in this code I wrote came to the 2nd player, not the 1st player. I tried to give socket.id to both users, I fixed it, but now nothing appears on the 2nd player.

socket.on('cardOpened', (data) => {
  var id = data.id;
  var img = data.img;

  $("#" + id + " img").attr("src", img);
  $("#" + id + " img").slideDown("fast");

  if (ImgOpened != "") {
      CheckMatch(id);
  }
});

mobile web – input type=”file” capture image upload then delete the temporary image on memory

I have an issue, that needs your help!!
(sorry for my bad English skills.. but trying to do the best !)

I build a page for fileUpload by in mobile web browser.
it works fine, but ..

there is an issue, for security.
it might happens all browsers, just now I’ve heard, it detected it on IOS safari.

problem is when user take a picture and then finished the upload then
the tester dumped the memory of browser.
and try to restore it to the picture what user uploaded.

it… restored!! ?!?!?!
it’s a secure issue ..

I want solve this problem… want reset or delete memory for read or upload the file …

I hope you understand what I trying to say TT_TT

$("input[type=file]").on("change", function(e){
  var reader = new FileReader();
  reader.addEventListener("load", readFileUplad);
  reader.addEventListener("loaded", function(ev){
     e = null;
     ev = null; 
     reader = null;
     $("input[type=file]").val('');
     $("input[type=file]").closet('form').get(0).reset();    
  });
  reader.readAsDataUrl(e.target.files[0]);
});

function readFileUplad(e){
  var data = new FormData();
  data.append("file", e.target.result);
  data.append("filename", "test.jpg");
  $.ajax({
     cache : false;
     ...
     complate : function(){
        data = null;
     }
  });
}

Create a MS Dev Box with API

I have currently problems with the token for the MS Dev Center service.

I call the API PUT {endpoint}/projects/{projectName}/users/{userId}/devboxes/{devBoxName}?api-version=2023-04-01 with a Bearer token like described:
AAD Token

  • I have the right authority.
  • I have the right scope “user_impersonation”
  • I use the implicit oauth2 flow

I successfully retrieved the token with the CLI:

az account get-access-token --resource https://devcenter.azure.com

but when I use the interactive flow in my react app, I get a 401.

Observations:
The jwt token retrieved with the CLI is encrypted
The browser “Try it” function under (https://learn.microsoft.com/de-de/rest/api/devcenter/developer/dev-boxes/create-dev-box?view=rest-devcenter-developer-2023-04-01) is also not working, when I log in with the account which should be able to create a dev box. (401)

Any ideas?

Splide.js options are not working except gap

I’m trying to add splide.js to my site. I’ve initialised the splide.js like this:

//initiate splide.js
            function initiateSplideElements() {
                var elms =
                    document.getElementsByClassName("plans-container");

                for (var i = 0; i < elms.length; i++) {
                    new Splide(elms[i], {
                        perMove: 1,
                        gap: "1.5rem",
                        mediaQuery: "min",
                        destroy: false,
                        perPage: 1,
                        breakpoints: {
                            960: {
                                perPage: 2,
                            },
                            1201: {
                                perPage: 3,
                            },
                        },
                    }).mount();

                    new Splide(".column-carousel", {
                        type: "loop",
                        perMove: 1,
                        gap: "1rem",
                        mediaQuery: "min",
                        destroy: false,
                        perPage: 1,
                        breakpoints: {
                            960: {
                                perPage: 2,
                            },
                            1201: {
                                perPage: 3,
                            },
                        },
                    }).mount();
                }
            }

            window.addEventListener("DOMContentLoaded", () => {
                initiateSplideElements();
            });

Although, the gaps are being applied, the arrows or breakpoints aren’t working. While resizing the page, for a moment the arrows become visible and then it vanishes again. Please click the ‘test plan popup’ at the bottom of this page to view the problem: buggy page

I had initialised the splide.js with the same options and content in this page and it is working (please scroll down and click the ‘test plan popup’ button).

I cannot figure out why the same splide is working in one page and not working in another. Please help.

Where to put cascade option with typeorm entities

I have two entities Order and Address and they have @ManyToMany relationship .

Address entity :

@ManyToMany(() => Order, (order) => order.address, { cascade: true })
@JoinTable()
order: Order;

Order entity :

@ManyToMany(() => Address, (address) => address.order, { cascade: true })
address: Address;

I need to know which entitiy need the cascade option and how can I identify that ?

Should I just use the cascade option in both entities ?