IntlTelInput on-the-fly formatting differs between Firefox and Chrome

Given the following Vue3 code :

<script>
....
import { fr } from "intl-tel-input/i18n"
import IntlTelInput from "intl-tel-input/vueWithUtils"
.....
</script>

<template>
......
<IntlTelInput
    id="client-phone"
    @changeNumber="(newNumber) => console.log(newNumber)"
    :options="{
        formatAsYouType: true,
        i18n: fr,
        initialCountry: 'fr',
        nationalMode: false,
        separateDialCode: true,
    }"
    :value="form.phone"
    :modelValue="form.phone"
    class="form-control"
/>
......
</template>

I can see that formattting is working on Chrome but not on Firefox :
a french number will be rendered as +33 6 12 34 56 78 on Chrome but +33612345678.

Just cannot figure out why…

How to Fix Procedure Block Naming Issue in App Inventor Backpack Flyout

I’m encountering a bug in App Inventor where procedure blocks added to the backpack don’t display their custom names in the flyout. Here’s the sequence of events:

  • I create a procedure block in the workspace and rename it from “procedure” which is the default name, to custom name “myBlock.”
  • I add this renamed block to the backpack using the right-click menu.
  • When I open the backpack and check the flyout, the block appears as “procedure” instead of “myBlock.”

The custom name (“myBlock”) is correctly stored in the block’s XML, as shown in the logs below, but the flyout still displays the default “procedure” name. This mismatch is confusing and disrupts my workflow.

Log When Adding to Backpack

Here’s the XML of the block when it’s added to the backpack:

<block type="procedures_defnoreturn" id="#4qif]FYIDIaBg$I~}%c" ...><field name="NAME">myBlock</field></block>

This confirms that the backpack stores the custom name correctly in the <field name="NAME"> tag.

Log When Opening the Backpack

When I open the backpack, the following logs are generated:

aiblockly-0.nocache.js:67146 Backpack contents: <xml><block xmlns="https://developers.google.com/blockly/xml" type="procedures_defnoreturn" id="#4qif]FYIDIaBg$I~}%c" x="-559.40625" y="-1050.87890625"><field name="NAME">myBlock</field></block></xml>
(anonymous) @ aiblockly-0.nocache.js:67146
Promise.then
AI.Blockly.Backpack.openBackpack @ aiblockly-0.nocache.js:67145
e @ aiblockly-0.nocache.js:3948
aiblockly-0.nocache.js:67148 Backpack contents length: 1
(anonymous) @ aiblockly-0.nocache.js:67148
Promise.then
AI.Blockly.Backpack.openBackpack @ aiblockly-0.nocache.js:67145
e @ aiblockly-0.nocache.js:3948
aiblockly-0.nocache.js:67153 Backpack block type: undefined id: #4qif]FYIDIaBg$I~}%c newBackpack: [object Element]
(anonymous) @ aiblockly-0.nocache.js:67153
Promise.then
AI.Blockly.Backpack.openBackpack @ aiblockly-0.nocache.js:67145
e @ aiblockly-0.nocache.js:3948
aiblockly-0.nocache.js:67155 Backpack contents: [object Element]

These logs indicate that the XML is retrieved with the correct name (“myBlock”), but the flyout receives an unprocessed [object Element] instead of a fully initialized block. This seems to cause the default “procedure” name to be displayed instead.


What I’ve Tried

I’ve dug into this issue and here’s what I’ve discovered:

  1. Verified Storage:
    The XML logged when adding the block to the backpack includes “myBlock” in the <field name="NAME"> tag, so the custom name is being stored correctly.

  2. Inspected Display Logic:
    When opening the backpack, the logs show the block type as undefined and the content as [object Element]. This suggests the flyout is receiving raw XML rather than a processed Blockly block object.

  3. Code Analysis:

    • The addToBackpack function serializes the block into XML with the custom name, which works as expected.
    • The openBackpack function retrieves the XML but passes it directly to the flyout’s show method without converting it into a proper block object.
    • I suspect the flyout requires fully initialized blocks (not raw XML) to display the correct name.

Based on this, I’ve proposed a potential fix by modifying the openBackpack function to convert the XML into Blockly blocks using Blockly.Xml.domToBlock. Here’s my suggested code:

AI.Blockly.Backpack.prototype.openBackpack = function(e) {
  if (e) {
    e.stopPropagation();
    if (e.button === 2) {
      this.flyout_.hide();
      this.openBackpackMenu(e);
      return;
    }
  }
  if (!this.isAdded && this.flyout_.isVisible()) {
    this.flyout_.hide();
  } else {
    this.getContents().then((contents) => {
      console.warn('Backpack contents: ' + contents);
      const len = contents.length;
      console.warn('Backpack contents length: ' + len);
      const newBackpack = [];
      for (let i = 0; i < len; i++) {
        newBackpack[i] = Blockly.Versioning.upgradeComponentMethods(Blockly.utils.xml.textToDom(contents[i]).firstChild);
        console.warn('Backpack block type: ' + newBackpack[i].type + ' id: ' + newBackpack[i].id + ' newBackpack: ' + newBackpack[i]);
      }
      console.warn('Backpack contents: ' + newBackpack);
      Blockly.hideChaff();
      this.flyout_.show(newBackpack);
    });
  }
};

This approach should turn the XML into initialized blocks, allowing the flyout to display “myBlock” instead of “procedure.” However, I haven’t tested this fully, and I’m unsure if it aligns with App Inventor’s specific implementation.


Question

The issue still persists despite my investigations, and I’m seeking guidance to resolve it. I’d like help with the following:

  • Is Blockly.Xml.domToBlock the right method to convert the XML into blocks for the flyout to display the custom name correctly?
  • Are there other parts of the App Inventor or Blockly codebase that might influence how procedure blocks are rendered in the backpack flyout?
  • Can someone with experience in App Inventor or Blockly confirm if my proposed fix is heading in the right direction, or suggest a better way to solve this?

I’d greatly appreciate any advice or solutions to fix this naming issue. Thanks for your help!

How to allow negative numbers also with 2 decimals points [duplicate]

I have this regex pattern which allows positive numbers only, no special characters, no negative numbers and with 2 decimal points.

I want to update this regex to allow negative/positive numbers, no special characters except "-" with 2 decimal points

Means -11.12 like this

<input type="text" class="form-control" id="txt-Cost" name="txt-Cost" maxlength="100" ng-model="Cost" />

 var txtCost= document.getElementById('txt-Cost');
            txtCost.addEventListener('keyup', restrictDecimalValues);

            function restrictDecimalValues(e) {
                var val = this.value;
                var re = /^([0-9]+[.]?[0-9]?[0-9]?|[0-9]+)$/g;
                var re1 = /^([0-9]+[.]?[0-9]?[0-9]?|[0-9]+)/g;
                if (re.test(val)) {
                    //do something here

                } else {
                    val = re1.exec(val);
                    if (val) {
                        this.value = val[0];
                    } else {
                        this.value = "";
                    }
                }
            };

Are top-level variables declared with const/let not supposed to be available to code in other script tags? [duplicate]

Here is a simple HTML document:

<html>
<head></head>
<body>
<script type="text/javascript">
A = 0;
var B = 0;
const C = 0;
let D = 0;
</script>
<script type="text/javascript">
console.log("A" in window);
console.log("B" in window);
console.log("C" in window);
console.log("D" in window);
</script>
</body>
</html>

true, true, false, and false get printed to the console, meaning C and D are not in the global scope. Is this supposed to be the case? If so, why can I see their values in the developer tools console of a browser?

how to track javascript programming elements/ features [closed]

im making a game for programmers with javascript. what I’m trying to do is create an attempts system in which the player can go to the browser console and type things in it, every time he types something the attempts are reduced by 1. but not for everything, if the player types console.log("test") an empty array or math with no reference to something, then no reduction will happen. when reaches 0, a game over the screen shows up.

this is my attempt logic

//  ATTEMPTS LOGIC

// Initialize attempts or get from localStorage
var allowedAttempts = 5;
let attempts = parseInt(localStorage.getItem("attempts")) || allowedAttempts;
localStorage.setItem("attempts", attempts);

let attemptReduced = false; // Prevent reducing multiple times in one execution

// Function to check for game over
function checkGameOver() {
  if (attempts <= 0) {
    setTimeout(() => {
      document.body.innerHTML =
        "<img src='../images/game over.png' style='width: 100vw; height: 100vh; object-fit: cover;'>";
    }, 100);
  }
}

// Function to safely reduce attempts & show warning
function reduceAttempts(reason) {
  if (!attemptReduced && attempts > 0) {
    attempts = Math.max(0, attempts - 1);
    attemptReduced = true;
    localStorage.setItem("attempts", attempts);
    console.warn(`⚠️ ${reason}. Attempts left: ${attempts}`);
    checkGameOver();
    setTimeout(() => { attemptReduced = false; }, 100); // Prevents recursion
  }
}

and this is where I track function element to reduce attempts but its not fully tracked yet as I can still type things and reduction doesn’t happen

 // Function.prototype.call override:
  // Always reduce when a function is called via .call()
  Function.prototype.call = (function (originalCall) {
    return function (thisArg, ...args) {
      reduceAttempts("Function call detected");
      return originalCall.apply(this, [thisArg, ...args]);
    };
  })(Function.prototype.call);

  
})();

// Check game over immediately on page load
checkGameOver();

test cases so far

@adyson 


// Logs to test with
// eval("console.log('Eval executed')"); ---> works
// new Function("console.log('Function Constructor executed');")(); ---> works
// console.log("Testing console.log tracking"); ---> doesnt need to work, harmless
// console.dir({ key: "value" }); ---> works
// console.table([{ name: "Alice" }, { name: "Bob" }]); ---> works
// function testFunction() { console.log("Function executed"); }  testFunction(); ---> does not work
// Math.floor(10.5); ---> does not work
// let obj = { name: "Hacker" }; Object.keys(obj); ---> works
// let arr = [1, 2, 3]; arr.push(4); ---> works
// Array.of(1, 2, 3); ---> not working
// Array.from([1, 2, 3]); ---> not working
// atob("SGVsbG8sIFdvcmxkIQ=="); ---> works
// btoa("Hello, World!"); ---> works

i been working on it for quite some time and some work, some don’t, sometimes I am hardly able to keep track of what is missing or working anymore.
anyone have any suggestions on how to do this? thanks,

I tried many different attempts and ways how to do this. but always get into a roadblock.

The most accurate way to do something at a constant rate in JS [duplicate]

I need to run a function every fixed time with maximum precision. For example, every 30 milliseconds a function will run. I tried this code:

this.interval = setInterval(() => {
            this.foo();
        }, 30);

But when I add the number of actions called in a certain time period with another time period of the same length, I get a different number!

Is there a way to solve this? That the accuracy in running the functions will be the same?

jQuery’s native slider does not actually slide while using mobile phone [duplicate]

First off, here’s my code:

$("#slider-range").slider({
  range: true,
  min: 0,
  max: 500,
  values: [75, 300],
  slide: function(event, ui) {
    $("#amount").val("$" + ui.values[0] +
      " - $" + ui.values[1]);
  }
});
$("#amount")
  .val("$" + $("#slider-range").slider("values", 0) +
    " - $" + $("#slider-range").slider("values", 1));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick-theme.css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>

<p>
  <label for="amount">Price range:</label>
  <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range"></div>

jsfiddle to test online:

https://jsfiddle.net/jt0h19bm/

I tested this code via PC, it works as it should.
via my mobile phone, however, it doesn’t actually slide, you may
click on certain spots and make the diameter change, sure,
but when trying to swipe on it left and right, as if you were trying
to skip certain profiles on dating apps, does not actually do anything.
Something with it’s long touch functionality is bugged, any help would be appreciated.

The most accurate way to do something at a constant time in JS

I need to run a function every fixed time with maximum precision. For example, every 30 milliseconds a function will run. I tried this code:

this.interval = setInterval(() => {
            this.foo();
        }, 30);

But when I add the number of actions called in a certain time period with another time period of the same length, I get a different number!

Is there a way to solve this? That the accuracy in running the functions will be the same?

jQuery’s native slider does not actually slide while using mobile phone

First off, here’s my code:

HTML:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick-theme.css"/>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
    
<p>
    <label for="amount">Price range:</label>
    <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range"></div>

JS:

$("#slider-range").slider({
    range: true,
    min: 0,
    max: 500,
    values: [75, 300],
    slide: function (event, ui) {
        $("#amount").val( "$" + ui.values[ 0 ] +
            " - $" + ui.values[ 1 ] );
    }
});
$( "#amount" )
    .val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
    " - $" + $( "#slider-range" ).slider( "values", 1 ) );

jsfiddle to test online:

https://jsfiddle.net/jt0h19bm/

I tested this code via PC, it works as it should.
via my mobile phone, however, it doesn’t actually slide, you may
click on certain spots and make the diameter change, sure,
but when trying to swipe on it left and right, as if you were trying
to skip certain profiles on dating apps, does not actually do anything.
Something with it’s long touch functionality is bugged, any help would be appreciated.

Shopify Google Autocomplete – Custom Form

I would like to add a custom form that would look like similar to the standard delivery form located in the check out page on my Shopify store. I would like to have the feature of suggested results available on it. My objective is to been able to store those address in the metadata from each customer.

Any idea how can I accomplish this? I tried using the Forms app but it did not work as it does not have the suggested values capability.

Why does my React app show user details after logout and refresh?

Problem: I am working on a React application that uses context to manage user state. When a user logs out, their details should be removed. However, after logging out and refreshing the page, the user details (username and email) are still displayed.

import React, { useContext, useState } from 'react';
import { UserContext } from '../UserContext/usercontext';
import { Navigate, useParams, useLocation } from 'react-router';
import { Link } from 'react-router';
import axios from 'axios';

export default function Account() {
  const { user, ready, setUser } = useContext(UserContext);
  const [redirect, setRedirect] = useState(null);
  const location = useLocation();
  const { subpage } = useParams();

  if (!ready) return <div>Loading...</div>;
  if (!user) return <Navigate to="/login" />;

  function isActive(path) {
    return location.pathname === path ? "bg-primary text-white" : " ";
  }

  async function logoutuser() {
    try {
      await axios.post('/logout');
      setUser(null); // Set the user state to null after logging out
    } catch (error) {
      throw error;
    }
  }

  return (
    <div>
      <nav className='w-full flex mt-8 justify-center gap-3 mb-8'>
        <Link className={`py-2 px-6 rounded-full ${isActive("/account")}`} to="/account">My Account</Link>
        <Link className={`py-2 px-6 rounded-full ${isActive("/account/bookings")}`} to="/account/bookings">My Bookings</Link>
        <Link className={`py-2 px-6 rounded-full ${isActive("/account/places")}`} to="/account/places">My Places</Link>
      </nav>

      {subpage === undefined && (
        <div className="mt-6 text-center max-w-lg mx-auto">
          <h2>Welcome, {user.name}!</h2>
          <p>Email: {user.email}</p>
          <button
            onClick={logoutuser}
            className="bg-primary m-2 hover:bg-pink-600 p-2 w-1/2 font-semibold text-white rounded-full"
          >
            Logout
          </button>
        </div>
      )}
    </div>
  );
}

Type error: Type ‘{ params: { titulo: string; }; }’ does not satisfy the constraint ‘PageProps’. Types of property ‘params’ are incompatible

I’m using NextJS 15 and I have the following page.tsx in the path app/article/[title]/page.tsx
the objective is to render the content returned by the api in a dynamic way where each article will have its own content.

import { notFound } from "next/navigation";
import Image from "next/image";


async function getArtigo(titulo: string) {
  try {
    const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/artigos?titulo=${encodeURIComponent(titulo)}`);

    if (!res.ok) return null;

    const data = await res.json();
    console.log(" Resposta da API:", data);

    if (Array.isArray(data) && data.length > 0) {
      return data[0]; 
    }

    return null;
  } catch (error) {
    console.error(" Erro ao buscar artigo:", error);
    return null;
  }
}


export default async function PaginaArtigo({ params }: { params: { titulo: string } }) {
  const { titulo } = params; 

  if (!titulo) {
    return notFound();
  }


  const artigo = await getArtigo(decodeURIComponent(titulo));

  if (!artigo) {
    return notFound();
  }

  return (
    <div className="container mx-auto px-4 py-8">
  
      {artigo.imageUrl && (
        <div className="flex justify-center mb-6">
          <Image
            src={artigo.imageUrl}
            alt={artigo.titulo}
            width={800}
            height={400}
            className="rounded-lg shadow-md"
          />
        </div>
      )}


      <h1 className="text-4xl font-bold mb-6 text-center">{artigo.titulo}</h1>


      <div className="max-w-3xl mx-auto text-gray-800 leading-relaxed">
        <div dangerouslySetInnerHTML={{ __html: artigo.body }}></div>
      </div>
    </div>
  );
}

however, when running an npm run build
I get this error

app/artigo/[titulo]/page.tsx
Type error: Type ‘{ params: { titulo: string; }; }’ does not satisfy the constraint ‘PageProps’.
Types of property ‘params’ are incompatible.
Type ‘{ titulo: string; }’ is missing the following properties from type ‘Promise’: then, catch, finally, [Symbol.toStringTag]

Drupal 7 module form_alter to set 2 date fields the same value if one changes

I need help to make a custom module to make 2 date fields in a content type to have always the same values using java script.

I have a content type called interpello . It has 2 date fields (pop-up calendar) named “data inizio” (field_data_inizio) and “data fine” (field_data_fine) in the format “d-m-Y h:m ”. Is there a way (using Ajax or Java script) to set the 2 date fields have always the same value, and if “data inizio” changes has to change “data fine” too. Thanks for any answer

JavaScript connect through http proxy manually for single request

Is it possible to connect through a http proxy using JavaScript in the browser just for a single request? I have written a basic example in Java:

    public static void main(String[] args) throws IOException {
        final Socket socket = new Socket(host, port);
        socket.getOutputStream().write("""
            GET %s HTTP/1.1
            Proxy-Authorization: %s
            
            """.formatted(path, proxyAuth).getBytes()
        );

        int c;
        while ((c = socket.getInputStream().read()) != -1) {
            System.out.print((char)c);
        }
    }

the values would be something like

host = proxy.example.com
port = 80
path = http://example.com/ (url to get)
proxyAuth = Basic ...

it works just fine. The problem with JavaScript is, when using fetch for example, that the api naturally puts a / infront of the path. So http://proxy.example.com/http://example.com/ becomes GET /http://example.com/ ... in the actual http request message. Is there a way to circumvent that? The proxy server is running squid porxy which I do not have complete control over and as far as I know there is no standard way of allowing a / infront of the url/path using squid proxy.

How can I bind a parameter in Javascript without losing debuggability?

In javascript, I have code which does:

item.callback = () => wrappedCallback(arg);

The problem with this is that if I inspect the callback property on item, i cannot determine what wrappedCallback is. Therefore I have changed this to:

item.callback = wrapppedCallback.bind(this, arg);

which works assuming that wrappedCallback has the same this parameter as the function. This isnt always true. How do I fix this when that is not the case? Is there a way of determining the “this” of the function so that I can pass that into the bind call?