How to use HTMLMesh to display a DOM element in AR view?

I am trying to display a DOM element in 3D space in AR view using HTMLMesh class from ThreeJS. Every time I try to add the element to the scene, it does not display and also I get this warning in the console:

WebGL: INVALID_VALUE: texImage2D: no canvas

This is my code:

   let html = [
            '<div style="width:100px; height:100px; background-color: red">',
            '<h2>Some info in a panel</h2>',
            '</div>'
        ].join("n");

    let div = document.createElement("div");

    div.innerHTML = html;

    let object = new THREE.HTMLMesh(div);
    object.position.set(position.x - 2, position.y + 2, position.z - 4);
    this.scene.add(object);

Unable to install react-navigation-header-buttons

I had installed an old version before,but i want to upgrade to version 8, but I dont know how to face these errors

these are the current errors i am facinh

   npm ERR! code ERESOLVE
    npm ERR! ERESOLVE could not resolve
    npm ERR!
    npm ERR! While resolving: [email protected]
    npm ERR! Found: @react-navigation/[email protected]
    npm ERR! node_modules/@react-navigation/native
    npm ERR!   @react-navigation/native@"~3.5.0" from [email protected]   
    npm ERR!   node_modules/react-navigation
    npm ERR!     react-navigation@"^3.11.1" from the root project
    npm ERR!   peer @react-navigation/native@"^3.1.1" from [email protected]
    npm ERR!   node_modules/react-navigation-drawer
    npm ERR!     react-navigation-drawer@"~1.2.1" from [email protected]  
    npm ERR!     node_modules/react-navigation
    npm ERR!       react-navigation@"^3.11.1" from the root project
    npm ERR!   1 more (react-navigation-stack)
    npm ERR!
    npm ERR! Could not resolve dependency:
    npm ERR! react-navigation-header-buttons@"8.0.0" from the root project
    npm ERR!
    npm ERR! Conflicting peer dependency: @react-navigation/[email protected]       
    npm ERR! node_modules/@react-navigation/native
    npm ERR!   peer @react-navigation/native@">=5" from [email protected]
    npm ERR!   node_modules/react-navigation-header-buttons
    npm ERR!     react-navigation-header-buttons@"8.0.0" from the root project  
    npm ERR!
    npm ERR! Fix the upstream dependency conflict, or retry
    npm ERR! this command with --force, or --legacy-peer-deps
    npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
    npm ERR!

Using a graphql value in a variable issues?

I created the following (using supertest) and placed in a function (removed imports etc for brevity)

module.export = {
function addThing (title, done) {
    const someGraphQL = `mutation {.....}`
    
    let the_id = ""

    request
    .post("/graphql") 
    .send({
        query: someGraphQL
    })
    .set("Accept", "application/json")
    .expect(200)
    .end((err, res) => {
        if (err) return done(err);
        the_id = res.body.data.id;
        console.log(res.body.data.id)
    })
    console.log(the_id)
    return the_id
  }
}

When I call this I can see the console.log with the “res.body.data.id”, but not the one in the variable.

I thought this may have been async type behaviour, but as I always see that console log for the res.body.data.id (but not for the variable (no matter where I put the variable) I am confused?

Create a comment | Google-SpreadSheet | nodeJS

I am trying to put a comment using NODEJS and the “Google Spread-Sheet” module, I have managed to write in cells, read, delete, but I can not put a comment in a cell, and the tutorials I see only teach discontinued forms, someone could help me? thank you very much.

const { GoogleSpreadsheet } = require('google-spreadsheet');
const creds = require('./googleSheetCredentials.json');

async function accessSpreadSheet() {
    const doc = new GoogleSpreadsheet('XXXXXXXXXXXX');
    await doc.useServiceAccountAuth(creds);
    await doc.loadInfo();
    const sheet = doc.sheetsByIndex[0];

    await sheet.addRow({
        Login: 'hello world', // column A
        Date: '2020-01-01' // column B
    });

    const row = await sheet.getRows();
    console.log(row);

    //await sheet.addComment('2', 'Login', 'Hello world'); Doesn't work 
}

accessSpreadSheet();

Cant figure out what is going wrong while using formik

consider the following code:

const handleEmployeeNumberChange = async (e, value, name) => {
        if (name === 'Employee Number') {
            const employee = await employeeServices.getByNumber(value);
            formik.setFieldValue('Employee Name', employee['Personal Information']['Employee Name']);
            formik.setFieldValue('Designation', employee.Company.Designation);
            console.log(employee.Company.Designation);
            formik.setFieldValue('Department', employee.Company.Department);
            const element = { target: { name, value } };
            formik.handleChange(element);
        }
    };

Some useful information:
The setFieldValue for the Department is working as expected, but not working for Designation. it is setting “” as the value, I logged the value of employee.Company.Designation and it is what is expected. I will post a small clip below for more clarity:

https://imgur.com/a/6Oduo7Z

addEventListener only works after the page is refreshed

I am actually new to JS and Css Variables and just testing out some.
And I came across this idea of changing the css variables through javascript while watching videos from javascript30.

In here, I have added the addEventListener method on the respective inputs. However, the values of the CSS Variables do not change unless I refresh the page.

Here are the codes.

Some HTML,

        <div class="spacing">
            <h2>SPACING</h2>
            <input type="range" class="spacing" data-sizing="px">
        </div>
        <div class="blur">
            <h2>BLUR</h2>
            <input type="range" class="blur" data-sizing="px">
        </div>
        <div class="color">
            <h2>COLOR</h2>
            <input type="color" class="color" class="color">
        </div>

For Css,

:root{
    --spacing: 10px;
    --color: #fb355f;
    --blur: 10px;
}

For JS,

const inputs = document.querySelectorAll('input');

const handler = (input)=>{
    const suffix = input.dataset.sizing || "";
    document.documentElement.style.setProperty(`--${input.className}` , input.value + suffix);
}

for(i=0; i<inputs.length; i++){
    inputs[i].addEventListener('change', handler(inputs[i]));
}

Isn’t it supposed to work as soon as I change the input value? Why does the page needed to be refreshed?
Thank you very much for answering.

How to apply html tag in a static string in react js

I have the static data in a component and passing it in another component. This static data is in the form of string and it contains some html tags. For Eg:

const obj = {
  ramdomData: "This is an example string.<br />Now I want to apply break here"
}

Now passing this data in another component:
<ExampleComponent data={obj} />

in ExampleComponent:

<div>
   {props.data.ramdomData}
</div>

In browser, it prints This is an example string.<br />Now I want to apply break here.
I want to apply break here.
How should I do it?

$_FILES is empty after uploading img.src

I am trying to upload a jpeg image into my localhost server.

var formData = new FormData();

fetch(document.getElementById("scanOutput").src)
     .then(res => res.blob())
     .then(blob => {
         const file = new File([blob], 'image.jpeg', blob);
         formData.append("file[]", file);
})

$.ajax({
     url: '/server.php',
     type: 'POST',
     data:formData,
     processData: false,
     contentType: false,
     cache:false,
     success: function(response) {
         alert(response)
     },
     complete: function() {}
});

I try to print the $_FILES array on my server:

print_r($_FILES);

The response I get is Array(). Why is my $_FILES array empty? How do I fix this?

How can I normalize and allow only positive integers on an input type number with redux form?

I am using the 8.3 version of redux-form, I am using the Field which should be allowed to to accept ONLY positive integers between the range 0-9999.

const REGEX_SPECIAL_CHARACTERS = /[@-_!#$%.&]/;

<Field
    mandatory
    step={1}
    name="timeout"
    type="number"
    min={0}
    max={9999}
    normalize={(value) => {
        console.log({value});
        return value?.split(REGEX_SPECIAL_CHARACTERS, 1).join('');
    }}
>
    Text
</Field>

I am using the normalize prop to validate this. If I enter 1.9, on blur it will set 1 which is ok. If I do -0 or -1 or just -n (n = any number) it just removes the entire value leaving an empty field and I need it to be ALWAYS 0 if there is whatever value going less than 0.

So any ideas on how I can improve this?

I do not know if maybe using the format prop but idk how to use it => https://redux-form.com/8.3.0/docs/api/field.md/#-code-format-value-name-gt-formattedvalue-code-optional-

ReactJS: click interaction not working on my content but working on header

Goal : display an iframe with a Youtube video and the user can click play/pause
Problem: I can’t click on anything in my main content, but it works just fine if I put it in the Navigation component or the Footer component
What I’ve tried: I tried many debugging to finally found this was the issue, but now I can’t figure out what to do

Here is the code of the Navigation component which works fine :

import React, { useState }  from "react";
import Navbar from "react-bootstrap/Navbar";
import Nav from "react-bootstrap/Nav";
import Container from "react-bootstrap/Container";
import { Link } from "react-router-dom";

import {NavLink} from "react-router-dom";
import {
    AiOutlineHome,
} from "react-icons/ai";
import {Button} from "react-bootstrap";

function Navigation() {
  const [expand, updateExpanded] = useState(false);
  const [navColour, updateNavbar] = useState(false);

  function scrollHandler() {
    if (window.scrollY >= 20) {
      updateNavbar(true);
    } else {
      updateNavbar(false);
    }
  }
  window.addEventListener("scroll", scrollHandler);

    return (
        <Navbar
            expanded={expand}
            fixed="top"
            expand="md"
            className={navColour ? "sticky" : "navbar"}
        >
          <Container>
            <Navbar.Brand href="/" className="d-flex">
              <p style={{marginTop: "15px"}}><strong className="main-name"> D</strong>egen <strong className="main-name">B</strong>ounty <strong className="main-name">H</strong>unter</p>
            </Navbar.Brand>
            <Navbar.Toggle
                aria-controls="responsive-navbar-nav"
                onClick={() => {
                  updateExpanded(expand ? false : "expanded");
                }}
            >
            </Navbar.Toggle>
            <Navbar.Collapse id="responsive-navbar-nav">
              <Nav className="ms-auto" defaultActiveKey="#home">
                <Nav.Item>
                  <Nav.Link as={Link} to="/" onClick={() => updateExpanded(false)}>
                    <AiOutlineHome style={{ marginBottom: "2px" }} /> Home
                  </Nav.Link>
                </Nav.Item>
              </Nav>
            </Navbar.Collapse>
          </Container>
        </Navbar>
    );
}

export default Navigation;

Here is the code of the Whitepaper component which doesn’t allow me to click on anything :

import React from "react";
import {Container, Row, Col} from "react-bootstrap";
import wp_1 from "../Assets/wp_1.png";

function Whitepaper() {
    return (<section>
            <Container fluid className="whitepaper-section" id="whitepaper">
                <Container className="whitepaper-content">
                    <div>
                        <button onClick={() => alert("test")}>Add</button>
                        <iframe
                            src="https://www.youtube.com/embed/E7wJTI-1dvQ"
                            frameBorder="0"
                            allow="autoplay; encrypted-media"
                            allowFullScreen
                            title="video"
                        />
                        {" "}
                    </div>

                    <Row>
                        <Col md={12}>
                            <img src={wp_1} alt="roadmap pic" className="img-fluid" style={{maxWidth: '50%'}}/>
                        </Col>
                    </Row>
                </Container>
            </Container>
        </section>);
}

export default Whitepaper;

So once again, when I pass my cursor over the button or the iframe, the cursor shape doesn’t change and I can’t click. I can select text, select image and right click everywhere.

In the CSS file I looked for pointer-events: none; but I don’t have anything like this

What is happening ?

Get body content of URL in JavaScript or PHP. (Get the YouTube Video ID from all the valid YouTube URLs)

Peace, Greeting. This is a very common question how to extract id from any correct youtube URL.

There are many answers to this but I have not found any answer which is 100% correct.

Then I created a script myself that could extract IDs from almost any valid yotube URL.

https://mnzrweb.github.io/p3/

This link is of the same tool I mentioned.
Information on how this tool works and which URLs this tool supports can be found at the link above.
This tool is based on JavaScript. I created this tool for the public and I want the public to be able to use it in their scripts so for that I have also created a direct functionally that does something like this.

https://mnzrweb.github.io/p3/?url=http://www.youtube.com/v/dQw4w9WgXcQ
output:
dQw4w9WgXcQ

Now how can user get this output in his PHP or JavaScript script. Something like this:

<?php &ytvidid = phpcode('https://mnzrweb.github.io/p3/?url=http://www.youtube.com/v/dQw4w9WgXcQ'); ?>

and &ytvidid should equal to returned content of upper URL (dQw4w9WgXcQ);

Using regex how to perform string match to get a different date format

I have two dateString formats like :date-f1:+2 and :date-f2:-1, if the incoming string is in date-f1:+2 format, I need to console.log as processedDate.format(“YYYY-MM-DD”), but if the incoming string is in :date-f2:-1 format, I need to console.log as processedDate.format(“DD/MM/YYYY”). I have tried the below, but getting an exception Cannot read properties of null (reading '1')", could someone please advise;

let dateString = ":date-f1:+2";  // or ":date-f2:-1"

    function datesParse(dateString) {
        
    let matchFormat = dateString.match(/^:date-f1:(|):date-f2:(?:([-+])([0-9]+)+)?$/);

        let processedDate = moment();
        if (matchFormat[1] === "-") {
            processedDate = processedDate.subtract(matchFormat[2], 'days');
            console.log("Date::"+processedDate.format("DD/MM/YYYY"));
        } else if (matchFormat[1] === "+") {
            processedDate = processedDate.add(matchFormat[2], 'days');
            console.log("Date::"+processedDate.format("DD/MM/YYYY"));
        } else if (matchFormat[1] === "-") {
            processedDate = processedDate.subtract(matchFormat[2], 'days');
            console.log("Date::"+processedDate.format("YYYY-MM-DD"));
        } else if (matchFormat[1] === "+") {
            processedDate = processedDate.add(matchFormat[2], 'days');
            console.log("Date::"+processedDate.format("YYYY-MM-DD"));
        }
        
    }
    
    datesParse(dateString);

Number Guessing game in javascript

I am a beginner javascript programmer. I made a very simple javascript number guessing game between 1 and 10. But it is not working. Could anybody take a look at this code and tell me what is wrong in this code.

// getting the value of a textbox
let guess=document.getElementById('text').value;

let GuessNumber=3;

// creating a function to check whether the userinput and the variable is same on the click of a button.
document.getElementById("submit").onclick=()=>{
    
    // if the user input and the number is same just display gift
    if(guess==GuessNumber){
        document.getElementById("P").innerHTML="Gift";
}

    // if the user input is not a number display 'it should be a number'
    else if(isNaN(guess)){
        document.getElementById("P").innerHTML="It should be a number";
}

    // if the user input is a number greater than 10 or less than 1 display 'it is a number between 1 and 10.
    else if(guess>11||guess<0){
        document.getElementById("P").innerHTML="It is a number between 1 and 10. Not beyond 10 or below"

}

    // or if it is not same as the guess number display 'better luck next time'
    else{
    document.getElementById("P").innerHTML="Better luck next time";
}
}

The problem here is ,these else if statement and if statement is not working. No matter what the input is it is just displaying better luck next time. here the guessing number is 3 and whenever i enter 3 then also it is displaying better luck next time. If it is not a number, then also it is displaying like this. What is wrong here. Could anybody please help.
The html of this code is here:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="index.css">
    <title>Document</title>
 </head>
 <body align="center">
    <h1>Number Guessing Game</h1>
    <h2>Guess a number between 1 and 10</h2>
    <h2>If your guess is correct we will give you a gift :) 
</h2>
    <input id="text" type="text" placeholder="Guess"> 
   <br><br>
    <button id="submit">submit</button><br><br>
    <p id="P"></p>
    <script src="index.js"></script>
</body>
</html>

Should I write the name of states, cities in capitals for JavaScript code while it’s naming conventions suggest camel case

I’m a junior JS developer, and I’m not sure what’s considered best practice for naming the variables that might be connected to the front-end interface.
For example, I’m trying to provide a list of the states and their cities; I was wondering if I should abide by the JS naming conventions for writing Object property names or write them in CAPITALS.
And also, should I put space between the multi-part names or better not?

For example:

let states = {
    Alabama: ["Alexander City", "Andalusia", "Anniston", "Athens"],
    Alaska: ["Anchorage", "Cordova"],
    Arizona: ["Lake Havasu City", "Window Rock"],
    Arkansas: ["Arkadelphia", "Benton"],
    California: ["Costa Mesa", "Mountain View"],
};