How to align all elements on same axis

I am trying to align all my elements on the same axis. The element can be anything: input, dropdown, button, etc. I am trying to accomplish this using only CSS. I know we can use MUI Stack component to align them but I only want to do it via CSS. The first image below shows an example of how it currently looks, which you can see is unaligned. The second image is the expected alignment that I want. Not sure how to proceed to make it aligned?

It is not aligned

It is aligned

import * as React from "react";
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";

export default function BasicButtons() {
  return (
    <span>
      <TextField id="standard-basic" label="Standard" variant="standard" />
      <Button variant="contained">Contained</Button>
      <Button variant="outlined">Outlined</Button>
    </span>
  );
}

Using PHP inside of CSS and JavaScript

Im trying to have a text line popup once the comment button is clicked for each line(row) dynamically.

When you click on the comment button, a line should popup under the buttons within the same row.

On DOM inspect, the lines and buttons all have unique names and id’s

I just cant get it to work as a unique event for each row.

Here is an image for reference

<div class="container-xxl flex-grow-1 container-p-y">
             
<h2 align="center"><?php echo $appname?></h2><br />
   <div class="form-group">
   <form name="add_name" id="add_name">
                    
   <div class="table-responsive">
      <table class="table table-bordered" id="dynamic_field">
         <?php while ($checks = mysqli_fetch_array($checksqry)) {
            echo '<tr>';
            echo '<td style="width: 20%">'.$checks['check_name'].' <br><br> 
            <input type="radio" class="btn-check" name="btn[' . $checks['id'] . ']" id="btnpass[' . $checks['id'] . ']" value="Pass">
            <label class="btn rounded-pill btn-outline-success" for="btnpass[' . $checks['id'] . ']">Pass</label>&Tab;&Tab;
                    
           <input type="radio" class="btn-check" name="btn[' . $checks['id'] . ']" id="btnwarning[' . $checks['id'] . ']" value="Warning">
           <label class="btn rounded-pill btn-outline-warning" for="btnwarning[' . $checks['id'] . ']">Warning</label>&Tab;&Tab;
                    
           <input type="radio" class="btn-check" name="btn[' . $checks['id'] . ']" id="btnfail[' . $checks['id'] . ']" value="Fail">
           <label class="btn rounded-pill btn-outline-danger" for="btnfail[' . $checks['id'] . ']">Fail</label>&Tab;&Tab;
                    
           <button onclick="myFunction()" type="button" name="comment[' . $checks['id'] . ']" id="comment[' . $checks['id'] . ']" class="btn btn-info" style="float: right"><img src="assets/comment.png" width="20px"></button> 
<br><br>
           <div id="commentlinediv[' . $checks['id'] . ']">
           <input type="text" class="text-line" placeholder="Type Comment Here" id="commentline[' . $checks['id'] . ']"/>
</div>
</td>';
echo '<tr>';}?>
                        
</table>
<input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />
</div>
</form>
</div>
</div>
input[type="text"] {
   border:none; /* Get rid of the browser's styling */
   border-bottom:1px solid black; /* Add your own border */
}

.text-line {
   background-color: transparent;
   color: black;
   outline: none;
   outline-style: none;
   border-top: none;
   border-left: none;
   border-right: none;
   border-bottom: solid #eeeeee 1px;
   padding: 3px 10px;
   width: 300px;
}
                
#commentlinediv[<?php echo $checks['id']?>]{
   display: none;
}
function myFunction() {
document.getElementById("commentlinediv[<?php $checks['id']?>]").style.display = "inline";
}

Map input to Key Value Pair

How do I map the vals to show be in key value pair

public getSearchHelpResult(evt: Event): void {
const vals = (evt as CustomEvent).detail;

this.showContinue = false;
[this.isGridVisible, this.showNoDataAlert] = [false, false];
this.gridColumns = [];
this.gridPayload.searchfilters = [];
this.gridPayload.appid = this.appId;
this.gridPayload.searchfield = vals.id;
this.gridPayload.searchfilters.push(vals);
console.log(vals)

right now the vals come as [{“ONE”:”9999″}] to look like this [{“id”:”ONE”,”value”:”9999″}]

I tried vals.map(val: {[key: string]: string}) => {
return {id: val.key, value: val.string}} but it didn’t work to get expected output.

Style Dictionary config.js – JSON not being transformed to CSS Variables successfully

I have a a JSON file that contains color and semantic theme variables, and an expected outcome I would like Style Dictionary to create in the CSS file using the provided “config.js” file.

Can you help me troubleshoot the config.js file so it successfully outputs the correct css variables?

Here’s the JSON content:

JSON file in my public repo

Here’s the expected outcome I would like in the CSS file, for the config.js file to propagate:

CSS file in my public repo

And here’s the content of my config.js file:

const StyleDictionary = require('style-dictionary');
const path = require('path');

// Define the Style Dictionary configuration
StyleDictionary.registerFormat({
  name: 'custom/css',
  formatter(dictionary) {
    console.log(dictionary); // Log the dictionary object to check its properties
    let css = '';

    // Generate CSS content from the tokens
    css += `:root {n`;
    Object.keys(dictionary.properties).forEach((key) => {
      const value = dictionary.properties[key];
      css += `  --${key}: ${value};n`;
    });
    css += `}nn`;

    // Generate light theme CSS
    css += `[data-theme="light"] {n`;
    css += `  /* Light theme styles */n`;
    css += `}nn`;

    // Generate dark theme CSS
    css += `[data-theme="dark"] {n`;
    css += `  /* Dark theme styles */n`;
    css += `}n`;

    return css;
  },
});

// Define the source JSON file
StyleDictionary.extend({
  source: [path.join(__dirname, '../json/fds-tokens-structure.json')],
});

// Define the platforms object
const platforms = {
  css: {
    transformGroup: 'css',
    buildPath: 'build/css',
    files: [
      {
        destination: 'fds-tokens-color.css',
        format: 'custom/css',
        options: {
          outputReferences: true,
        },
      },
    ],
  },
};

// Build the Style Dictionary for all platforms
StyleDictionary.buildAllPlatforms({ platforms });

I’m getting this error when I run “style-dictionary build”:

  Object.keys(this.options.platforms).forEach(function (key) {
         ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Object.buildAllPlatforms (/Volumes/T5/GitHub/FDS/packages/tokens/style-dictionary/node_modules/style-dictionary/lib/buildAllPlatforms.js:30:10)
    at Object.<anonymous> (/Volumes/T5/GitHub/FDS/packages/tokens/style-dictionary/config.js:56:17)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.extend (/usr/local/lib/node_modules/style-dictionary/lib/extend.js:95:15)

Thanks, and have a good weekend.

How to programatically open push notifications

Could you kindly help me write a script that simulates the opening of push notifications in a new tab without user interaction. I want the push notifications to open in a new tab without me having to click on them.

I tried autohotkey script and tampermonkey script but they did not work. I was expecting to see push notifications open in a new tab without me having to click the notifications themselves.

extension controlling Crynchyroll video

I’m creating a chrome extension where i can control the html5 video on a page.

It works fine for Youtube and Vimeo but i’m having trouble for Crunchyroll.

Crunchyroll apparently has their video inside of an iframe. So i cant seem to access it without running into cross-origin errors.

Would need to be able to do basic video controlling like play, pause, see and set current time etc.

Extensions do exist for Crunchyroll so it has to be possible somehow.
Cant seem to find a solution, most forums and stuff just get the html5 video the regular way.
But that does not work. Either everybody is wrong, Crunchy just changed or I’m missing something.

possible solutions:

  • can i inject a script into the iframe too, like my extension is injecting into the main tab content now?
  • are their custom controls that are available for Crunchyroll?

tried the regular way:

html5player = document.querySelector('video');

nothing found

tried connecting to the iframe:

var iframe = document.querySelector('iframe'),video;
if (iframe) {
  html5player = iframe.contentWindow.document.getElementsByTagName('video');
}

this will get you a cross-origin error

Why does scrollTop not take the value being set

I am running into an issue when setting scrollTop where, when set with a value, it reverts back to it’s old value. The result is a momentary flash as the scrollbar moves and then goes back to it’s original position. I am seeing this issue cross browser and cross operating systems.

There are some additional particulars to this issue which makes it even more weird.

  1. It only happens while you are manipulating the scrollbar. If you use your mouse wheel there is no problem.
  2. In the example I am providing, if you disable, for the outer div, either the overflow CSS attribute or both border radius attributes this problem goes away. To add to my misery the example I am providing is a HIGHLY boiled down version of the original program. In this program the outer div is beyond my control, and(hold on to your seat), exists OUTSIDE of the iframe my code is running in. THAT’S RIGHT! Some how the CSS is affecting stuff running inside an iframe. I checked and I cannot see the iframe change size or have it’s own CSS or attributes being modified in any way.

I have a fiddle which demonstrates the issue, however, to see how removing the CSS also removes the issue, it’s best ran on it’s own from your IDE. I think jsFiddle has their own CSS somewhere outside the iframe it’s running in causing the problem.

https://jsfiddle.net/CodeMedic42/oxut78b2/3/

I provided a debugger statement to stop your debugger where the issue is occurring. To see the issue, scroll down, using your mouse and dragging the scroll bar, to 1985:11 and when you get just past that, new items are added to the top of the list which pushes the scroll bar down. What I am doing is then resetting the scrollbar back to the spot where is was moved from.

If you haven’t guessed I am making an infinite list component. I ran into this issue while running it on Storybook.

Also if you are asking why I am using “overflow-anchor: none;” I will angrily refer you to Apple to ask them why Safari on Mac and iOS is the only modern browser that does not support it. If they did I would not be here right now.

I need to provide code for the jsFiddle link or StackOverflow won’t accept it. It’s just a copy from the fiddle.

function chooseColor(index) {
    const v = index % 10;

    if (v === 0) {
        return 'purple';
    }

    if (v === 1) {
        return 'orange';
    }

    if (v === 2) {
        return 'green';
    }

    if (v === 3) {
        return 'yellow';
    }

    if (v === 4) {
        return 'magenta';
    }

    if (v === 5) {
        return 'red';
    }

    if (v === 6) {
        return 'black';
    }

    if (v === 7) {
        return 'brown';
    }

    if (v === 8) {
        return 'pink';
    }

    return 'cyan';
}

function List() {
    const listRef = React.useRef();
    const itemsRef = React.useRef();
    const itemsRemoved = React.useRef(false);
    const shiftInfoRef = React.useRef(null);

    const [itemsMeta, setItemsMeta] = React.useState({ from: { year: 1974, month: 3 }, to: { year: 1991, month: 8 }});

    const items = React.useMemo(() => {
        const builder = [];
        let startingMonth = itemsMeta.from.month;
        let endingMonth = 12;

        for (let yearCounter = itemsMeta.from.year; yearCounter <= itemsMeta.to.year; yearCounter += 1) {
            if (yearCounter === itemsMeta.to.year) {
                endingMonth = itemsMeta.to.month;
            }

            for (let monthCounter = startingMonth; monthCounter <= endingMonth; monthCounter += 1) {
                startingMonth = 1;

                const color = chooseColor(yearCounter);
              
                const text = yearCounter + ':' + monthCounter;

                builder.push(<div key={yearCounter * 12 + monthCounter}style={{color: 'white', fontSize: 48, margin: 20, backgroundColor: color}}>{text}</div>);
            }
        }

        return builder;
    }, [ itemsMeta ]);

    const handleScroll = React.useCallback(() => {
        const scrollOn = 140;

        const targetChild = itemsRef.current.childNodes[scrollOn];
        const item = itemsRef.current.childNodes[scrollOn + 1];

        const childRect = targetChild.getBoundingClientRect();
        const listRect = listRef.current.getBoundingClientRect();
        const itemRect = item.getBoundingClientRect();

        if (!itemsRemoved.current && childRect.bottom < listRect.top) {
            console.log('Add items');
            itemsRemoved.current = true;

            setItemsMeta({ from: { year: 1979, month: 4 }, to: { year: 1991, month: 8 }});

            shiftInfoRef.current = {
                previousPosition: itemRect.top,
                item,
            };
        }
    });

    React.useLayoutEffect(() => {
        const targetChild = itemsRef.current.childNodes[70];

          targetChild.scrollIntoView({
            block: 'start',
            inline: 'start',
        });
    }, []);

    React.useLayoutEffect(() => {
        if (shiftInfoRef.current == null || itemsRef.current == null) {
            return;
        }

        const { previousPosition, item } = shiftInfoRef.current;

        const itemRect = item.getBoundingClientRect();

        const scrollTop = listRef.current.scrollTop - (previousPosition - itemRect.top);

        shiftInfoRef.current = null;

        debugger;
        // This fails when scrolling using the scrollbar, but works when using the mouse wheel. #rage
        listRef.current.scrollTop = scrollTop;
    });

    return (
        <div style={{
            position: 'absolute',
            width: '100%',
            height: '100%',
            borderTopLeftRadius: 5,
            borderBottomLeftRadius: 5,
            overflow: 'hidden',
        }}>
            <div
                ref={listRef}
                className="list"
                onScroll={handleScroll}
            >
                <div style={{ fontSize: '128px', margin: 20 }}>
                    Top Header
                </div>
                <div ref={itemsRef}>
                    {items}
                </div>
            </div>
        </div>
    );
}
:root {
    scroll-behavior: smooth;
}

* {
    box-sizing: border-box;
}

html,
body,
#app {
  padding: 0;
  margin: 0;
  background-color: white;
  height: 100%;
}

.list {
  height: 100%;
  overflow: auto;
  box-sizing: border-box;
  overflow-anchor: none;
}

Show and Hide DIV’s after 5000 seconds when .wpcf7-mail-sent-ok

I made a Contact Form 7 with a custom “Thank You!” message that appears after wpcf7mailsent.

I need it to reverse after seconds. My current code does not work:

addEventListener('wpcf7mailsent', function(event) {
    event.preventDefault();
    document.querySelector('.qtWRP').style.display = 'none';
    document.querySelector('.inputBTMx').style.display = 'none';
    document.querySelector('.cap').style.display = 'none';
    document.querySelector('.qtWRP2').style.display = 'block';
});

wpcf7Elm.addEventListener( 'wpcf7-mail-sent-ok', function( event ) {
jQuery ( 'form.wpcf7form' )[1000].reset();
}, false );;

Appreciate any help.

enter image description here

enter image description here

Add a text line in php table on button click

I have a table for vehicle inspections. It has a pass, warning, fail button for each check(each row). It also has a comment button. I would like a text line to popup under the check in the same row once the comment button is clicked. I would also like to have the comment turn red if warning or fail is clicked as it would be required. Any tips would be greatly appreciated!

Click here to see my web app example

This is my current code for the table:

<div class="container-xxl flex-grow-1 container-p-y">
             
<h2 align="center"><?php echo $appname?></h2><br />
   <div class="form-group">
   <form name="add_name" id="add_name">
                    
   <div class="table-responsive">
      <table class="table table-bordered" id="dynamic_field">
         <?php while ($checks = mysqli_fetch_array($checksqry)) {
         echo '<tr>';
         echo '<td style="width: 20%">'.$checks['check_name'].' <br><br> 

         <input type="radio" class="btn-check" name="btn[' . $checks['id'] . ']" id="btnpass[' . $checks['id'] . ']" value="Pass">
         <label class="btn rounded-pill btn-outline-success" for="btnpass[' . $checks['id'] . ']">Pass</label>&Tab;&Tab;
                    
         <input type="radio" class="btn-check" name="btn[' . $checks['id'] . ']" id="btnwarning[' . $checks['id'] . ']" value="Warning">
         <label class="btn rounded-pill btn-outline-warning" for="btnwarning[' . $checks['id'] . ']">Warning</label>&Tab;&Tab;
                    
         <input type="radio" class="btn-check" name="btn[' . $checks['id'] . ']" id="btnfail[' . $checks['id'] . ']" value="Fail">
         <label class="btn rounded-pill btn-outline-danger" for="btnfail[' . $checks['id'] . ']">Fail</label>&Tab;&Tab;
                    
         <button type="button" name="comment[' . $checks['id'] . ']" id="comment[' . $checks['id'] . ']" class="btn btn-info" style="float: right"><img src="assets/comment.png" width="20px"></button> </td>';
echo '<tr>';}?>
                        
      </table>
   <input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />
   </div>
   </form>
</div>
</div>

Ive tried this for my event listener, but not currently working:

document.getElementById ("comment[<?php echo $checks['id']?>]").addEventListener ("click", () => {
                       document.getElementById("commentline[<?php echo $checks['id']?>]").classList.toggle('showMe')
                    }, false);

How can i implement value of input like an search?

I’m currently facing an issue with setting the value of an input field for search functionality in my React application. I’ve attempted to achieve this using both state management (useState) and the React hook useRef(), but unfortunately, neither approach seems to be working as expected.

Here’s what I’ve tried so far:

import React, { useEffect, useState } from 'react';
import "./App.css";
import MovieList from './Components/MovieList';
import NavBar from './Components/NavBar';

function App() {
 const [data, setData] = useState([]);
 const [search, setSearch] = useState('');

 useEffect(() => {
  fetch(`http://www.omdbapi.com/?s=${search}&apikey=a8b01dfe`)
    .then(respone => respone.json())
    .then(json => setData(json.Search))
    .catch(error => console.error(error))
 }, [search]);

 const handleSearch = (e) => {
  setSearch(e.target.value);
 }

 return (
   <div>
     <MovieList movie={data}/>
     <NavBar search={handleSearch} />
   </div> 
 );
}

export default App;

import React from 'react';

function NavBar(props) {
  return (
    <div>
      <input ref={props.search} type='text' placeholder='Search...'/>
    </div>
  );
}

export default NavBar;

Here is how i render movies:

import React from 'react';
import "./Style/MovieList.css"

function MovieList(props) {
 const item = document.querySelector(".movie-list-main-container");

  window.addEventListener("wheel", function (e) {
    if (e.deltaY > 0) item.scrollLeft += 100;
    else item.scrollLeft -= 100;
  });

  return (
    <div className='movie-list-main-container'>
      {props.movie.map((item, index) => (
        <div className='movies' key={index}><img src={item.Poster} alt={item.Title}/></div>
      ))}
    </div>
  );
}

export default MovieList;

Capturing data in JS from hundreds of HTML elements with unpredictable IDs

I’m struggling with getting data from a div in PHP to process in an external JavaScript file.

In a PHP file I have a while-loop that generates, from a DB, a lot of HTML divs (up to 250 records at a time) with various values from the DB inside them. For each div/record there is a button so people can copy one specific value to their clipboard.

My problem is that I can’t select the value by ID as that is different and unpredictable for each element.

PHP simulation for testing purposes:

<?php
    
    // Simulate a loop
    echo '<div class="item_bio">';
        $value = uniqid();  // A randomly generated value to simulate the value we get from the DB
        echo '<span>'.$value.'<button class="buttons value_copy_button" id="'.$value.'" data-valuetocopy="'.$value.'">Copy</button></span>';
    echo '</div>';
    
    echo '<hr>';
    
    echo '<div class="item_bio">';
        $value = uniqid();  // A randomly generated value to simulate the value we get from the DB
        echo '<span>'.$value.'<button class="buttons value_copy_button" id="'.$value.'" data-valuetocopy="'.$value.'">Copy</button></span>';
    echo '</div>';
    // End of simulated loop
    
    echo '<script src="./assets/scripts/copy_value_to_clipboard_tester.js"></script>';

?>

JavaScript in copy_value_to_clipboard_tester.js:

const button = document.querySelector("button");

button.addEventListener("click", copyToClipboard);
      function copyToClipboard() {
        window.focus() // Focus the window to make sure writing to the clipboard is allowed
        navigator.clipboard.writeText(document.getElementById('copyValue').dataset.valuetocopy).then()
}

The challenge, and the reason I’m using an external JS file, is that I can’t use inline JavaScript because of the Content Security Policy (CSP) on the site that doesn’t allow any inline JS. That means I can’t use onclick with the unique value as I would normally have done.

How do I capture that $value from the button that was clicked if there are potentially hundreds of buttons with unpredictable IDs on the page?

Back Button in Onsen UI Navigator Triggering Validation Checks

I’m building out a small vehicle inspection form application for my wife’s company using Onsen UI. The app allows users to visually and functionally check that a vehicle is free from damage and functioning as expected upon delivery. Users should be able to freely navigate between eight pages in the app, and when they get to the last page all data will be stored to a MySQL database. Before advancing to the next page in the flow, some simple validation checks are performed to make sure required data has been input.

All was working fine until I began adding validation checks into the flow. The problem I’m seeing is that when the Back button is clicked, the validation checks that should be performed when the Next button is clicked are triggered. I’m struggling to understand why the checks are triggering.

Each page has checks such as the following performed when the Next button is clicked:

function next(){
            // Check each set of radio buttons to see if checked
            var envelopeChecked = checkRadios('envelope'),
                insuranceChecked = checkRadios('insurance'),
                accidentChecked = checkRadios('accident'),
                registrationChecked = checkRadios('registration'),
                manualChecked = checkRadios('manual');    
            
            // If all radio buttons checked, the initial validity test is passed    
            var isFormValid = envelopeChecked &&
                insuranceChecked &&
                accidentChecked &&
                registrationChecked &&
                manualChecked;
                console.log(isFormValid);
            
            // TO DO: Add logic to check for entered value description for any observed damages
            
            if (!isFormValid) {
                console.log('Missing radio options page3');
            } else {
                const navigator = document.querySelector('#navigator');
                /*navigator.pushPage('page4.html');*/
                navigator.bringPageTop('page4.html');
            }

checkRadios and checkText are simple validation checks to make sure all radio button groups have an option checked and all required textarea inputs have text. Any ideas on why these validation checks are triggering on the Back button?

Tealium custom container javascript running with page view trigger but not with click (add to cart tracking)

I have a custom container tag that I have stripped down to one console.log statement for debugging purposes.

When I set the rule for this tag to all pages or to specific pages and turn on Tealium debugging output, the console statement comes in the output right after

SENDING: [my tag’s tealium UID]

After some work to set up the correct trigger that fires on a link event for add to cart, I can see it still SENDING: but I don’t think the custom container tag’s javascript runs and there is no console output from the tag.

I don’t have an extension associated with this tag, although I am going to need one.

How does this JS sort when it has a function inside that returns multiple things?

I created a secondary sort and its working but I don’t understand how.

    this.report.sort((a, b) => {
        if(a[col] > b[col]) return 1;
        if(a[col] < b[col]) return -1;
        if(a[secondaryFilter] > b[secondaryFilter]) return  1;
        if(a[secondaryFilter] < b[secondaryFilter]) return -1;
    });

I thought when the sort sees the first return, it would exit the sort. How does it reach the secondary filter sort?

The code works and I learned the syntax online but I don’t get how it works.