Why is wordpress custom customizer control underscore js template rendered using the content_template function not showing form html element

I have a custom wordpress fonts-picker customizer control that allows a user to select their desired fonts on their site. The HTML bit of the control is rendered via the content_template method of the WP_Customize_Control class as below:

public function content_template() {
            ?>
            <div class="font-picker-wrapper">
                <div class="fonts-picker-header">
                    <# if ( data.label ) { #>
                        <span class="customize-control-title">
                            {{ data.label }}
                        </span>
                    <# } #>
                    <# if ( data.description ) { #>
                        <span class="description customize-control-description">
                            {{ data.description }}
                        </span>
                    <# } #>
                </div>
                <div class="font-picker-body">
                    <form role="form" name="font-picker-form" class="ivio-font-picker">
                        <label for="{{data.id}}-font-family-select" class="description customize-control-description">
                            <?php echo esc_html(__("Font Family", "ivio")); ?>
                        </label>
                        <select name="{{data.id}}-select" id="{{data.id}}">
                            <# if ( data && data.systemFonts ) { #>
                                <optgroup id="ivio-system-fonts" label="System Fonts">
                                    <# _.each(data.systemFonts, function(font, key) { #>
                                    <option value="{{font.family}}" <# (data.value && (data.value.fontFamily===font.family))? print("selected") : print("") #>>
                                        {{ font.family }}
                                    </option>
                                    <# }) #>
                                </optgroup>
                            <# } #>
                            <# if (data && data.googleFonts ) { #>
                                <optgroup id="ivio-google-fonts" label="Google Fonts">
                                <# _.each(data.googleFonts, function(font, key) { #>
                                    <option value="{{font.family}}" <# (data.value && (data.value.fontFamily === font.family))? print("selected") : print("") #> >
                                        {{ font.family }}
                                    </option>
                                <# }) #>
                                </optgroup>
                            <# } #>
                        </select>
                        <div class="selected-font-variants">
                        </div>
                        <div class="selected-font-subsets tag-cloud">
                        </div>
                    </form>
                </div>
            </div>
            <?php
        }

The problem is when the above HTML markup is rendered on the customizer frontend, the opening and closing form HTML tags do not get rendered yet the children they contain get rendered. I need the form tags to be rendered as the form is submitted via JavaScript where the form is converted to json using the form.serializeArray() javascript function. Any help will be much appreciated. I’ve been stuck here for quite a while now.

Executing PHP file using another PHP file

Hey guys I was practicing PHP and I am stuck

so, I have HTML file at where I used Fetch function of js to take user’s email id from Front end and send it to register.php which tells either this email is saved in db or not. if not then it will save it into db, now my question is if email wasnt in db and if i store it in db i have to verify it by sending a email to that email id so what i have done is write a code of sending verification mail into register.php but as register.php is kind of API so executing mail varification functionality it will timeout at js side so my question is, is there any way such that i write mail verification functionality in another php which execute if there is no email address stored in DB than register.php trigger that file. I do have thought that js trigger than other php file once register.php respond but I dont want to do so, BTW you can also give me some keywords on which I can research to do this task It may be silly question as I am exhausted now but if so I am so sorry

How to keep the same tab open after refresh javascript / css

I am trying to keep selected tab active on refresh with css and js. Tried and checked with some question already been asked here but none of work for me. Don’t know what to do.
html code:


<div class="container">
      <div class="title">Machine learning : Prediction ET0 </div>
      <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'daily')" id="defaultOpen">Journalier</button>
        <button class="tablinks" onclick="openCity(event, 'hourly')">Horaire</button>
        <button class="tablinks" onclick="openCity(event, 'Exdaily')">Excel journalier</button>
        <button class="tablinks" onclick="openCity(event, 'Exhourly')">Excel Horaire</button>


      </div>

<script>
function openCity(evt, data) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");


  }
  document.getElementById(data).style.display = "block";
  evt.currentTarget.className += " active";
}
</script>

A function to unify different types of react artifacts

We are creating a base library for administration panel (something similar to react-admin).

However, in react world, objects can be of a lot of types. There is no single consistency.

Let’s say you have a component called Action, and your library user should provide a list of it for you.

These are possible things that you might get:

// a single item, as a JSX variable
const Actions = <Action />

// an array of items, as a JSX variable
const Actions = <>
   <Action />
   <Action />
</>

// an arrow function, but returning a single JSX result
const Actions = (params) => <Action />

// an arrow function, but returning an array of JSX results
const Actions = (params) => <>
    <Action />
    <Action />
</>

// an arrow function, having body, returning a single JSX result
const Actions = (params) => {
    return <Action />
}

// an arrow function, having body, returning an array of JSX results
const Actions = (params) => {
    return <>
         <Action />
         <Action />
    </>
}

// or they might give lowercase variables, etc.

And there might be other possible ways that I don’t know.

This makes wring code very frustrating and difficult. Because for simple JSX variable you should use interpolation syntax ({actions}), for function components you should render using <Actions />, etc.

Is there a function in react which we can use to wrap all of these types in an empty fragment and unify them?

Why my javaScript code in not working with my react Component?

I cannot add client-side javaScript into my React App component (LeftSection.js). Can anyone please tell me what is wrong with my code? The one possible answer is that I am adding my javaScript code before JSX (HTML) which does not allow it to work. So, where should I put my script? Also, I am sure that I am also not allowed to put tag in the JSX code.

Here is the code:

import './LeftSection.css';
import React from 'react';

function LeftSection () {
    var coll = document.getElementsByClassName("collapsible");
    var i;

    for (i = 0; i < coll.length; i++) {
        coll[i].addEventListener("click", function() {
            this.classList.toggle("active");
            var content = this.nextElementSibling;
            if (content.style.display === "block") {
                content.style.display = "none";
            } else {
                content.style.display = "block";
            }
        });
    }
    
    return (
        <div className = 'left-section'>
        <div id = "tool_tree">
            
            <ul>

                <li>
                    <a className = "collapsible">CLM</a>
                    <ul className = "content">  
                        <li>
                            <a className = "collapsible">Commons</a>
                            <ul className = "content"> 
                                <li><a href="#">Workstation</a></li>
                            </ul>
                        </li>
                        
                        <li>
                            <a className = "collapsible">Electrical Characterization</a>
                            <ul className = "content">
                                <li><a href="#">ECL: 4294A Precision Impedance Analyzer</a></li>
                                <li><a href="#">ECL: Cascade 1200 (room temp)</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>

            </ul>
        </div>
        </div>
    );
};

export default LeftSection;

I will really appreciate your help!
Thanks.

ReactTS: How I add a click event in a image to mimetize the hamburguer menu?

this is the case
part 1 — part 2 with final result

To practice I’m trying to transform html, css and js websites in ReactTS websites. I looking to understand better how everything works.

In the parts showed before he inserts in the image a onClick=”toggleMenu()” and puts a id=menuList in the ul.

After this, he opens a script and write:

var menuList = document.getElementById('menuList');

menuList.style.maxHeight = "0px";

function togglemenu(){
    if (menuList?.style.maxHeight == "0px") {
        menuList.style.maxHeight = "130px";
    } else {
        menuList?.style.maxHeight = "0px";
    }
}

How can I write this in ReactTS?
I tried to create a component, import and call the function inside the image and ul but this didn’t work. I’m a little confuse.

Exclude sub DIV from Javascript & DOM

I have two div. <div class="card" id="openWebsite"> and sub div <div class="card__btn">

If someone clicks on my root div they will get redirected to example.com and when someone clicks sub div they are redirecting to example.com & example.net, they are getting redirected two both link in two new tab.

I want, if someone clicks on root div they should get redirect to example.com and when someone clicks on sub div button they should only be redirected to example.net not example.com

how to exclude sub div <div class="card__btn"> from javascript.

Code :

const webPage = document.querySelectorAll("#openWebsite");
webPage.forEach((e) => {
  e.addEventListener("click", () => {
    const site = e.getAttribute("data-site");
    window.open(site, "_blank") || window.location.replace(site);
  });
});
  <div class="card" id="openWebsite" data-site="https://example.com">
    <div class="card__btn">
      <a href="https://example.net">
        Visit Site
      </a>
    </div>
  </div>

Already tried from jQuery exclude elements with certain class in selector , https://api.jquery.com/not/ , document.querySelector exclude part of DOM, https://www.w3schools.com/jsref/met_document_queryselectorall.asp

document.querySelectorAll("#openWebsite").not(".card__btn");

and

document.querySelectorAll(".card").not(".card__btn");

Image Error showing up randomly for no reason HTML, JavaScript

I am a beginner at HTML and Stack Overflow. I was trying to make this thing where there is an image that changes every few seconds. I was able to get this done but for some reason although all my 3 pictures show up, I have an extra image error icon that shows up once in a while and I don’t know why. I only have 3 images so I am not sure why this image error icon shows up. Any help would be greatly appreciated.

This is the link to the code:
https://onecompiler.com/html/3y5dpewsu

React + styled components -> justifyContent not working

I have a problem using Styled Components in my native React app. I want to have 1 styled component(item) nested into another styled component(container). I want to set justify-content in container to flex-start, but it is not working. My item component is automatically centered in the middle of screen. This problem occurs only when nesting one styled component into another one. If nest anything else, for example h1, div, p, etc… justifyContent works just fine. But it is not effecting my item styled component. Also justify-self has no effect either.

here is code:

export const GalleryContainer = styled.div`
   display: flex;
   flex-direction: column;
   padding: 70px 0;
   min-height: 500px;
   width: 100%;
   justify-content: start;
   align-items: flex-start;
   background-image: url(${spaceBackground});
   background-size: cover;
   background-repeat: no-repeat;
   background-position: center;
`;
export const GalleryItem = styled.div`
   display: flex;
   flex-direction: row;
   flex-wrap: wrap;
   width: 90%;
   max-width: 1200px;
   min-height: 100px;
   justify-content: flex-start;
   padding: 25px;
   margin: auto;
   background-color: ${palette.darkGrey};
`;

any ideas how to solve this please?
Thanks a lot.

The data duplication returns after sending multiple requests at some time

I have an API which returns to me a list of subjects to articles.
The amount of this subjects depends on a number provided in an input field.
Please, see the sceenshot:
an UL of subjects with an input field

The problem starts at the moment when I quickly type the numbers, for example “11” or “13”.
Some data is returned as duplicated.
Please, see the sceenshot:
duplicated data after quickly typed input number
The same happens when I quickly delete the number.
Please, see the sceenshot:
the subject appears while there have to be no subjects at all

My html attached:

    <ul class="articles-list"></ul>
    <input type="number" name="limit" id="limit" />
    <script src="./index.js"></script>

My pure JS attached:

document.addEventListener("DOMContentLoaded", fetchArticles);

limit.addEventListener("input", (e) => {
  updateInput(e);
  removeArticles();
  fetchArticles();
});

// 10 articles are fetched by default
// if quickly install a limit.value - articles are repeated // slow down the request
async function fetchArticles() {
  limit.defaultValue = 15;

  if (limit.value === "") return;

  let url = `https://api.spaceflightnewsapi.net/v3/articles?_limit=${limit.value}`;
  let response = await fetch(url);
  let data = await response.json();

  displayArticles(data);
}

// choose HTMLCollection because I work with li elements only
function displayArticles(data) {
  let articlesList = document.getElementsByClassName("articles-list")[0];

  data.map((article) => {
    let li = document.createElement("li");

    li.innerHTML = article.title;

    articlesList.appendChild(li);
  });
}

function updateInput(e) {
  limit.value = e.target.value;
}

// on some iteration i meets articlesList.childElementCount
// don't use for loop for li elements because after deleting the first li the next li becomes the first one
function removeArticles() {
  let articlesList = document.getElementsByClassName("articles-list")[0];
  let items = articlesList.children;

  while (items.length > 0) {
    items[0].remove();
  }
}

Could you please explain me what is the problem?
Could you please advise on how to solve it? I don’t even understand what to google.

I can use only pure JS.

How upload photo using fetch?

I try to upload photo from my PC using fetch, but code below doesn’t work. Url is right. What is the problem?

 static async sendPostFormDataRequest(url) {
    let formData = new FormData();
    formData.append("nameField", "C://sample.jpeg");
    fetch(url, {
        method: "POST",           
        body: formData
    })
}

“Jump to Message” Button

Hi so basically I’m making a suggestion command. Once the user ran the command it will reply “Suggestion Submitted” with “Jump to Suggestion” url button but I’m getting error with the button. Here’s my code


const { MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require("discord.js");

const db = require("quick.db")


module.exports = {
    name: "suggestion",
    description: "Create or reply to a suggestion",
    userPermissions: "",
            options: [{
            name: "create",
            type: 1,
            description: "Create a suggestion",
            options: [{
                name: "suggestion",
                type: 3,
                required: true,
                description: "The suggesiton you want to give"
            }],       
            }, {
            name: 'set-channel',
            type: 1,
            description: "Select the suggestion channel",
            options: [{
                name: "channel",
                type: 7,
                required: true,
                description: "The channel where I should send the suggestions"
            }]
        }],
                      
                      
      /**
     *
     * @param {Client} client
     * @param {CommandInteraction} interaction
     * @param {String[]} args
     */

    run: async (client, interaction, args) => {
      await interaction.deferReply(); 

       const option = interaction.options.getSubcommand()
             
             const suggestion = interaction.options.getString("suggestion")
             
        const channel = interaction.options.getChannel("channel")

           const id = interaction.options.getString("id")

          const status = interaction.options.getString("status")

          const response = interaction.options.getString("response")
            
      const guildId = interaction.guild.id

      let c = await db.fetch(`suggestion_${guildId}`);

     if (option === "create") { 
         if (!c) { return interaction.editReply("<:pollno:979743680124555286> No suggestion channel were found!") 
          } else {
    
       const suggestembed = new MessageEmbed()
       .setTitle("New Suggestion!")
       .setColor("2F3136")
       .setDescription(suggestion)
       .setFooter(interaction.user.username)
       
       const url = suggestembed.url
       
       const row = new MessageActionRow()
       .addComponents(
             new MessageButton()                    .setLabel('Jump to Message')
            .setStyle('LINK')
            .setURL(url)
           )
        const doneembed = new MessageEmbed()
        .setTitle("Suggestion Submitted!")
        .setDescription("Your Suggestion was submitted")
        .setColor("2F3136")
        
        interaction.editReply({ embeds: [doneembed], components: [row] })
        
      c.send({ embeds: [suggestembed] })
         }
         } else if (option === "set-channel") {
            if (!interaction.member.permissions.has("MANAGE_GUILD")) return interaction.editReply({ content: "<:pollno:979743680124555286> You don't have enough power to execute this command", ephemeral: true })
                

            if (channel.type !== "GUILD_TEXT") return interaction.editReply({ content: "<:pollno:979743680124555286> Invalid Channel Type!", ephemeral: true })

            await db.set(`suggestion_${guildId}`, channel.id);
             const last = new MessageEmbed()
             .setTitle("Suggestion Setup!")
             .setDescription("Suggestion channel have been setup")
             .setColor("2F3136")
             
             interaction.editReply({ embeds: [last] })
             }
       }  
}

The Error

Error: MessageButton must be a String

Hope to get the some help with this as this have become the issue for me that make my development stopped! Thanks

Run a python script from Chrome extension

I’m building a Chrome extension, and I want the extension to pass data to a Python script which would do some magic and then return a response to the extension.

I want to make it as user-friendly as possible; thus I’d prefer not to have the user manually run the python script.

How can I make the extension run the script?

(Please note that I’m looking to build an extension – thus I can’t move everything to be Python-only)