Why PHP Code Sometimes Doesn’t Work with JavaScript Despite Using preventDefault()

When integrating PHP and JavaScript, you might encounter situations where your PHP code doesn’t work as expected, even if you’ve used preventDefault() to prevent the page from refreshing

  • the integration between PHP and JavaScript and ensure that your code works as expected.

  • interactions between PHP and JavaScript to ensure that data is transmitted and processed correctly

ReferenceError: createBrowserRouter is not defined when using “as Router” in React [closed]

When I write createBrowserRouter as Router, I am getting this error:

ReferenceError: createBrowserRouter is not defined.

But when I don’t use as Router, my code works properly. Why is this happening? Which one is correct? I am confused

import React from "react";
import ReactDOM from "react-dom/client";
import Header from "./components/Header";
import Body from "./components/Body";
import About from "./components/About";
import { createBrowserRouter, RouterProvider } from "react-router";

const AppLayout = () => {
  return (
    <div className="App">
      <Header />
      <Body />
    </div>
  );
};

const appRouter = createBrowserRouter([
  { path: "/", element: <AppLayout /> },
  { path: "About", element: <About /> },
]);

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<RouterProvider router={appRouter} />);

Webpack + import() swallows top-level errors?

E.g. if I have an “error.ts” file that just contains:

throw new Error('error');

Then, “fn.ts” imports that file:

import './error';

export default function fn() {}

If I want to dynamically import “fn.ts” from a variable containing the file name, I’d need to use require() or import(). If I import “fn.ts” using require(), I get Error: error as expected:

const { default: fn } = require(filename); // this line throws
fn();

If I import “fn.ts” using import(), I get:

Cannot read properties of undefined (reading 'default')

.

const { default: fn } = await import(filename); // no error
fn(); // this line throws

What are some possible explanations for why this is occurring? I’m using the latest Webpack 5.97.1. My Webpack config is too complicated to share here, but there’s no weird custom plugins etc affecting import().

How to change theme into circular thumbnail in Coloris?

I’m using latest version of coloris and looking at the provided examples page I need to make component with
a ‘circular thumbnail’ theme.

<input type="text" id="accent_color" name="accent_color"
  class="accent_color"
  value="{{ $accentColor }}" data-coloris>

I tried to change theme of the component with this code:

<script src="/js/coloris.min.js"></script>
<script>
  $(document).ready(function() {
    Coloris.setInstance('#accent_color', { 
      theme: 'polaroid', 
      themeMode: 'dark',   
      alpha: true 
    });
    // ...

Using that code, the dark theme is applied, but not theme – it is still default:

enter image description here

Which is the correct way to assign ‘circular thumbnail’ theme?

How in coloris to change theme into Circular thumbnail?

Using latest version of coloris( https://coloris.js.org/ ) in php8 / bootstrap 5.1.3 / jquery 3.6.1 app
and looking at examples at https://coloris.js.org/examples.html page I need to make component with
Circular thumbnail theme :

<input type="text" id="accent_color" name="accent_color"
    class="form-control"
    value="{{ $accentColor }}" data-coloris>

and I try to change theme of the component with code :

 <script src="/js/coloris.min.js"></script>

<script>
    $(document).ready(function() {
        Coloris.setInstance('.accent_color', { theme: 'polaroid', themeMode: 'dark',   alpha: true });
        ...

After that code dark themeMode is applied, but not theme – it is still default :

enter image description here

!

Which is the correct way to assign Circular thumbnail theme ?

Dynamically Adjust Layout Based on null Values

I’m working on a JavaScript project where I need to dynamically adjust a layout configuration based on certain values being null. The layout consists of rows with items positioned either on the left or the right. When a value is null, the corresponding item should be removed and other items should shift up to fill the space, maintaining their left or right positions.

Default Layout Structure:

const defaultLayout = [
  [{
    label: 'Material Type:',
    key: item.materialType || 'N/A',
    position: 'left',
    multiline: false,
  }, {
    label: 'Project Location:',
    key: project.location.city || 'Unknown',
    position: 'right',
    multiline: false,
  }, ],
  [{
    label: 'Condition:',
    key: item.condition || 'Unspecified',
    position: 'left',
    multiline: false,
  }, {
    label: 'Availability Dates:',
    key: `From ${formatDate(item.availableFrom)} To ${formatDate(item.availableTo)}`,
    position: 'right',
    multiline: true,
    fixedY: 246,
  }, ],
  [{
    label: 'Dimensions:',
    key: item.dimensions || 'Standard',
    position: 'left',
    wrap: true,
    multiline: true,
  }, ],
  [{
    label: 'Product Description:',
    key: item.description || 'No description available.',
    position: 'left',
    wrap: true,
    multiline: true,
    maxLines: 2,
  }, ],
  [{
      label: 'Reusable Quantity:',
      key: item.reusableQuantity !== undefined ? `${item.reusableQuantity} units` : 'N/A',
      position: 'left',
      multiline: false,
    },
    {
      label: 'Unit Price (Excl. Tax):',
      key: item.unitPrice ? `$${item.unitPrice.toFixed(2)}` : 'Contact for price',
      position: 'right',
      multiline: false,
    },
  ],
  [{
    label: 'Minimum Order Quantity:',
    key: item.minOrderQty || '1',
    position: 'left',
    multiline: false,
  }, ],
];

Also, for example, lets say we have ‘material condition’ and a ‘dimension’ property that are null so the ‘description’ will end up at the ‘material’ position the ‘reusable quantity’ will be in the ‘state’ position and ‘minim order quantity’ will be in the same row as ‘price’

Note that description, project location and availability will never be null

What I want it to do is split left and right in to to arrays then I looped. This works until ‘description’ then everything will mess up the constrains that if i was in the current row that had in the default table 2 values and that i will be switching to a position where they was one value like description i take the whole row if im in single row and ill move on to single row like (description moving to dimension) i take the whole row 2

adjustLayout(layout) {
  // Flatten the layout to make it easier to work with
  const flatLayout = layout.flat()

  // Filter out fields with null or undefined keys
  const filteredLayout = flatLayout.filter(field => field.key != null)
  
  // Reassign positions
  const leftFields = filteredLayout.filter(field => field.position === 'left')
  const rightFields = filteredLayout.filter(field => field.position === 'right')

  // Reconstruct the layout
  const newLayout = []
  let leftIndex = 0,
    rightIndex = 0

  while (leftIndex < leftFields.length || rightIndex < rightFields.length) {
    const row = []
    console.log('check default row length', layout[newLayout.length].length)
    console.log('check default row value', layout[newLayout.length])

    if (leftIndex < leftFields.length) {
      row.push(leftFields[leftIndex])
      leftIndex++
    }
    if (
      rightIndex < rightFields.length &&
      (newLayout.length === 0 ||
        layout[newLayout.length].length !== layout[newLayout.length - 1].length) //thisd is causing a problem ccause 0-1
    ) {
      row.push(rightFields[rightIndex])
      rightIndex++
    }
    if (row.length > 0) {
      newLayout.push(row)
    }
  }

  return newLayout
}

Dropdown options displaying outside it and not selectable

I have a dropdown menu with set up exactly like other dropdown menu’s. This drop down menu however, displays its options underneath it and does not allow me to select an item.

Also, when I add options to it using JavaScript, only those options are displayed correctly and are selectable.

HTML code:

<div id="itemRemover" class="dropdown-wrapper" style="display: none;">
  <span class="label">Select item to be removed:</span>
  <select id="-removelist-" class="dropdown">
    <option value="" disabled selected></option>
  </select>
  <button id="btnRemove" class="button" style="margin-top: 5px;">Remove</button>
</div>

JavaScript code used to add options to the dropdown:

//Create new option
const option = document.createElement('option');
option.textContent = item;
// Add option to the list
document.getElementById('itemRemoverMenu').appendChild(option);

Image of the problem:
enter image description here

I tried using overflow: visible on the parent and I tried making the other elements on the page smaller as I thought the page getting too populated was the issue.

querySelectorAll does not work for element

I am having trouble trying to select the child nodes of an element having the specified div class.

In the debug window, I have checked that the variable element is indeed Element type. The line docContentRef.current.querySelectorAll shows there are existing elements with the practice-note class.

Now when I retrieved the element having child nodes with the practice-note class and using the line element.querySelectorAll, it does not return the expected list of 4 items.

enter image description here

Webpage – tracking position and reposition yourself based on a floating image on the side

This is a bit difficult to explain so here is an image that should help: https://prnt.sc/8b51WKZJB_TN

What I’d like to see if and how could a page element be created that would be

  • floating on the side
  • would essentially show the whole page in a minimized version
  • showing where you are on the page (see red rectangle on the image)
  • and if clicked anywhere on it would scroll you to that section

There must even be a special name to this.

Has this been done somewhere? Any of you have any examples I could look at?
Generally how should I even start?

P.S. I am setting up a Webflow based website, and this would be in our blog.

Is storing login password in localStorage in SPA with all JS scripts hosted in the same server OK for security?

Is storing login username and password in localStorage in SPA with all JS scripts hosted in the same server OK for security?

I have an Angular SPA app with all app scripts and 3rd party scripts hosted on the same server. For automatically and silently login again after the JWT access token expires and the refresh token expires, I store the username and password in LocalStorage.

Is the app secured from attacks by cross site scripting?

ResizeObserver loop completed with undelivered notifications in vue js script

when i am add this :scroll=”{x:’120px’}” i am having error like this ResizeObserver loop completed with undelivered notifications

<a-table :scroll=”{x:’120px’}” :row-selection=”rowSelection” :columns=”columns” :data-source=”paginatedData” :pagination=”pagination” @change=”handleTableChange” rowKey=”id” :customRow=”customRow” >

About the front end [closed]

Are there any learning methods or learning processes and any good learning websites that can recommend?

I have studied software engineering for three years at school. During this time, I also learned different computer languages, but they were all basic knowledge and I have never decided on a goal. Recently, I need an internship for graduation and found that internship positions generally require proficiency in one direction, so now I plan to start learning front-end languages ​​in depth for work. So I would like to ask if there are any learning methods or learning processes and any good learning websites to recommend,thank you.

Remark-definition-list titles should be bold

I want to add definition lists support for MDX files, hence that’s why I added the remark-definition-list node package.

Unfortunately, titles are not rendered with bold font, just a regular one.

This what my mdx-options configuration look like:

import remarkGfm from 'remark-gfm'
import remarkDefinitionList, { defListHastHandlers } from 'remark-definition-list'

const MDXOptions: SerializeOptions = {
    mdxOptions: {
        remarkPlugins: [remarkGfm as any, remarkDefinitionList],
        rehypePlugins: [...]
    }
}

I also noticed the package renders all elements as divs instead of using dd, dt, dl. Is that normal?

<div>
   <div>First Term</div>
   <div>
      <p class="font-aaa-text dark:text-zinc-50 text-base font-normal leading-7 py-2 text-zinc-950">This is the definition of the first term.</p>
   </div>
   <div>Second Term</div>
   <div>
      <p class="font-aaa-text dark:text-zinc-50 text-base font-normal leading-7 py-2 text-zinc-950">This is one definition of the second term.</p>
   </div>
   <div>
      <p class="font-aaa-text dark:text-zinc-50 text-base font-normal leading-7 py-2 text-zinc-950">This is another definition of the second term.</p>
   </div>
</div>

I tried adding { handlers: defListHastHandlers }, inside mdxOptions, as well as I tried adding different remark packages into the remarkPlugins array, but none of those seemed to work.

Which one should I use when defining schema and resolvers in GraphQl

I saw different ways of using schema and resolvers in graphql with expressjs. Which one should I use, and which one is recommended?

1:

`const schema = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: "HelloWorld",
        fields: () =>({
            message: {
                type: GraphQLString,
                resolve: () => "Hello World"
            }
        })
    })
})`

2:

`const schema = buildSchema(`
    type RootQuery{
        message: String!
    }
    Query {
        query: RootQuery
    }
`);`

`const resolver = {
    message: () => "Hello World"
}`

i’m using this way when defining schema and resolvers.

`const schema = buildSchema(`
    type RootQuery{
        message: String!
    }
    Query {
        query: RootQuery
    }
`);`

`const resolver = {
    message: () => "Hello World"
}`