How To Make A Submit Button In A Certain Form For A Different Form?

I have a button that is defined inside a form:

<form action="" method="POST" id="form1">
    <input type="hidden" name="form_name" value="form1" />
    <input type="text" placeholder="Write something" name="text_input"/>
    <button type="submit" form="form2" id="submit_button2">Click to save other form!</button>
    <button type="submit" id="submit_button1">Click to save form!</button>
</form>

And another form:

<form action="" method="POST" id="form2">
    <input type="hidden" name="form_name" value="form2" />
    <input type="text" placeholder="Write something else" name="other_text_input" />
</form>

When I hit submit_button2 I would like to only get the inputs only in form2 and when I click on submit_button1 I would like to get all the inputs only in form1 in my flask server. However, it doesn’t work and I don’t understand why.

Vue using js in script to refer to elements

So I’m following a post in stackoverflow Convert Text to Image using javascript but in vue Js. I can’t seem to get this working, it’s throwing me this error

serve.vue?bf12:27 Uncaught TypeError: Cannot read properties of null (reading 'getContext')
    at eval (serve.vue?bf12:27:1)
    at Object../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader-v16/dist/index.js?!./dev/serve.vue?vue&type=script&lang=js (app.js:997:1)
    at __webpack_require__ (app.js:849:30)
    at fn (app.js:151:20)
    at eval (serve.vue?5c0c:1:1)
    at Module../dev/serve.vue?vue&type=script&lang=js (app.js:962:1)
    at __webpack_require__ (app.js:849:30)
    at fn (app.js:151:20)
    at eval (serve.vue?061e:1:1)

Here’s my code, it’s simple enough

<template>
  <div id="app">
    <canvas id="textCanvas" height="20" />
    <img id="image" />
    <br />
    <textarea id="text" />
  </div>
</template>

<script>
var tCtx = document.getElementById("textCanvas").getContext("2d"), //Hidden canvas
  imageElem = document.getElementById("image");

document.getElementById("text").addEventListener(
  "keyup",
  function () {
    tCtx.canvas.width = tCtx.measureText(this.value).width;
    tCtx.fillText(this.value, 0, 10);
    imageElem.src = tCtx.canvas.toDataURL();
    console.log(imageElem.src);
  },
  false
);
</script>

how to get multiple inputs type date values to console with checking if empty

I have six inputs type date, four of them are read-only. When I choose a date on the first one, I calculate that date and put the values on the read-only inputs, and I choose a date in the last input after that I click the button.
I want to console.log() all of the dates, and get errors if the the inputs are empty.
How can I achieve all of this.

Here’s what I have done:

import { React, useState } from "react";
import moment from "moment";


export default function Test() {

  const [date, setdate] = useState({date1:"",date2:"",});
  const [error, seterror] = useState("");



  const handleChange = (event) => {
    setdate(event.target.value)
  }

  const handleClick = (event) => {
    event.preventDefault();
    if (!isNaN(date.date1)||!isNaN(date.date2)) {
      seterror("error")
      
    }else{
      
      seterror("")
    }
  };

  function addDays(date, days) {
    var result = new Date(date);
    result.setDate(result.getDate() + days);
    var res = moment(result).format("YYYY-MM-DD")
    return res;
  }



  return (
    <div>
      <div className="widget widget-chart-one">

        <form>

          <label>تاريخ القرار</label>
          <input type="date" className="form-control" name="date1" onChange={handleChange}
          />
          

          <label>تاريخ النشر  </label>

          <div className="form-group row  mb-6">
            <div className="col-sm-6">
              <input type="date" className="form-control" value={date} readOnly />

            </div>
            <div className="col-sm-6">
              <input type="date" className="form-control" value={addDays(date, 15)} readOnly/>
            </div>
          </div>
          <label >فترة البحث العمومي  </label>

          <div className="form-group row  mb-6">
            <div className="col-sm-6">

              <input type="date" className="form-control" value={addDays(date, 15)} readOnly />
            </div>
            <div className="col-sm-6">
              <input type="date" className="form-control" value={addDays((addDays(date, 15)), 9)} readOnly/>
            </div>
          </div>
          <label>تاريخ الاجتماع</label>
          <div className="form-group row  mb-10">
            <div className="col-sm-12">
              <input type="date" className="form-control" name="date2" />

            </div>
            
          </div>
          <button className="mr-2 btn btn-primary" type="submit" onClick={handleClick}> تأكيد</button>
          <div>
              {error && <small className="text-danger"> {error} </small>}
            </div>


        </form>
      </div>
    </div>
  );
}

How to upload images one by one to server in react

I want to upload 4 images one by one to server, in response i will get 4 urls and save all urls in a state in react

const multiStatement= async(e) => {
     const files = e.target.files;
     const fd = new FormData()

    files.map(img=>{
     fd.append(`file`, img)
    const res =  uploadDocument(fd)

    console.log( res.data.url)//save this url 
   })
}
<input type="file" id="file" multiple name="file" onChange={multiStatement} />

Unable to access js module classes from browser console?

I am using “classses” with a bunch of static members to keep my very professional code somewhat organized. Like so:

import { UINav, UIDimension } from "./interface.js";
import { Dimension } from "./dimension.js";
import { InputFlex } from "./input.js";
function main() {
    Dimension.init();
    UIDimension.init();
    UINav.init();
    InputFlex.start();
}

My question: Why am I getting, for instance, Uncaught ReferenceError: InputFlex is not defined when I want to check stuff from inside the browser console, but all methods from the imports all execute as expected? How can I find my beloved “classes” from inside the browser?
I am using TypeScript also but I doubt that matters?
Edit: The files are fetched from a localhost server.

redux-toolkit nextjs server-side rehydration

I am trying to:

  1. get server-sided headers (req.headers.x-my-custom-header)
  2. getInitialProps (_document) dispatch x-my-custom-header to store
    (server-sided) <- PROBLEM
  3. rehydrate x-my-custom-header to client

_document.tsx:

MyDocument.getInitialProps = async (context: DocumentContext) => {
  const initialProps = await Document.getInitialProps(context);
  const isServer = context.req;
  if (isServer) {
    // const site = context.req?.headers['x-site']
    store.dispatch(setSite('foo')); // <- setting state to 'foo'
  }
  const initialState = store.getState();
  console.log('initialState', initialState); // <- has 'bar' in it
  return {
    ...initialProps,
    initialState,
  };
};

my slice

import { createSlice, Slice } from '@reduxjs/toolkit';

export const name = 'settings';

export enum Sites {
  foo = 'foo',
  bar = 'bar',
}

export type SettingsState = {
  site: Sites;
};

const initialState: SettingsState = {
  site: Sites.bar,
};

const slice: Slice<SettingsState> = createSlice({
  name,
  initialState,
  reducers: {
    setSite(state, action: { type: string; payload: Sites }) {
      state.settings.site = action.payload;
    },
  },
});

export const { setSite } = slice.actions;

export default slice.reducer;

Any ideas what could be the problem here?

Round borders with DT datatables in R

I would like round borders on my DT table. Unfortunately my JS skills are very limited (or even inexistent) thus I would be very happy if somebody could help me to figure out how to implement round borders on a DT table in R.

This is my code so far:

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      paste0(
        "$(this.api().table().header()).css({
          'background-color': 'black',
          'color': 'white',
          'border-top-left-radius': '4px',
          'border-top-right-radius': '4px'
          });"
      ),
      "}"
    )
  )
)

The last part border-top-left-radius does not work but something like this would be the solution. I think this answer has the solution in pure JS but I need somebody to help me to implement this snippet in my R code.

How to add :after and :before icon that change on click button dropdown?

With after and before I’m trying to change the dropdown icon when it is open or closed. So far I have not achieved any results, I am relatively new to all this and I do not understand how I can achieve the result, can someone help me please?

Actually I don’t even know if that’s the right way to do this.

var dropdownBtn = document.querySelectorAll('.drop_btn');
lastOpened = null; //Add this for toggling dropdown

dropdownBtn.forEach(btn => btn.addEventListener('click', function() {
  var dropCont = this.nextElementSibling;
  dropCont.classList.toggle("show");
  
  //Add this for toggling dropdown
  if (lastOpened && lastOpened !== dropCont)
      lastOpened.classList.remove("show");
      lastOpened = dropCont;
}));
.drop_btn {
  background: #e0e0e0;
  padding: 10px;
  margin: 5px 0px 0px 0px;
}

.drop_btn:before {
  font-family: fontAwesome;
  content: 'f077';
  float: right;
}

.drop_btn:after {
  font-family: fontAwesome;
  content: 'f078';
  float: right;
 }

.drop_btn:hover {
  background: #000;
  color: #fff;
}

.drop_container {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.2s ease-out;
}

.drop_container.show {
  max-height: 300px;
  transition: max-height 0.3s ease-in;
}

.drop_container > .item {
  display: flex;
  flex-direction: column;
  margin-left: 10px;
  padding: 10px 0px 0px 0px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">

<div class="dropdown-menu">

<div class="drop_btn">One</div>
<div class="drop_container">
  <a class="item" href="#">Contact Us</a>
  <a class="item" href="#">Visit Us</a>
</div>

<div class="drop_btn">Two</div>
<div class="drop_container">
  <a class="item" href="#">Contact Us</a>
  <a class="item" href="#">Visit Us</a>
</div>

</div>

How can I change the background colour of an list item when on a certain section of a page?

I have a navbar on the top of my page that stays on top of the page at all times;

<div>
<header>
    <nav class='cf'>
        <ul class='cf'>
            <li>
                <a href='#showcase'>Home</a>
            </li>
            <li>
                <a href='#vr-solutions'>VR Solutions</a>
            </li>
            <li>
                <a href='#clients'>Clients</a>
            </li>
            <li>
                <a href="#manufacturing">Manufacturing</a>
            </li>
            <li>
               <a href="#products">Products</a>
            </li>
            <li>
                <a href="#about-us">About Us</a>
            </li>
            <li>
                <a href="#/">Latest News</a>
            </li>
            <li>
                <a href="#/">Gallery</a>
            </li>
        </ul>
            <a href='#' id='openup'>Dropdown</a>
    </nav>
</header>   
</div>

In the body section I have sections with id tags, to which the navbar links scroll to.

<section class="section section-dark" id="vr-solutions">
    <p> content </p>
</section>

<section class="section section-light" id="clients">
    <p> content </p>
</section>

/* and so on */

How do I, with javascript or jquery, change the background colour of the ‘li VR Solutions’ to red if said section is visible on page, and then back to the previous colour once off screen, and move to the ‘li Clients’ once it is visible on screen?

The idea is an indicator of where you are on page shown by the navbar.

How to target last flex item

I have a list of divs that can be either display:none or display:flex dynamically depending on a few conditions.

How do I check, since this is dynamic, what is the last div showing display flex?

My code is something like this:

<div class="container">
  <div style="display: flex"></div>
  <div style="display: none"></div>
  <div style="display: flex"></div>
   <div style="display: none"></div>
</div>

As I say, the children might or might not be display:flex and might not necessarily be in this order or might be more items than this or not. I need to identify the last item with display:flex so I apply a borderBottom with javascript.

Best (and scaleable) way to select from multiple services in javascript

Im in the process of building a system that can communicate with 1 or multiple CMS’s within the project. Each of these services have a slightly different structure in the request but are looking to return the data in a json that follows a fixed format for the application.

My current approach is to have something similar to below.

///apiRequestA.js
function TestA()
{
    console.log("Service A")
}

export {TestA}
///apiRequestB.js
function TestB()
{
    console.log("Service B")
}

export {TestB}
///masterService.js

import {TestA} from "@/service/apiRequestA";
import {TestB} from "@/service/apiRequestB";
const Service = "A"
function Test()
{
   if(A)
   {
     return TestA()
   }
   else if(B)
   {
     return TestB
   }
}

This would work, but feels like for a rather large collection of requests / if was to expand to a 3 or more end points (could be likely), then the masterService can become very long and messy.

From C# background i would have all the base functions called the same and then use a preprocesser to determine which service to import into master and then just have the master service call the function.

How can I pass data from my angular front to php symfony Back

I have an angular application that works as a timeScheduler, But the database is huge so i decided to fetch data when the user scroll in the scheduler. for this i must send to the Back-end the date of the last fetching so it can fetch other data starting from that date is it possible to send data in the http request url ?
thank you

Unable to resolve module ‘hooks.js’

Hello,

I am currently trying to display a Leaflet map on a react-native application.
I use the Expo Snack online editor for testing.
I imported the “leaflet” and “react-leaflet” packages:

{
  "dependencies": {
    "leaflet": "1.8.0",
    "react-leaflet": "4.0.0",
    "expo-constants": "~13.1.1",
    "@expo/vector-icons": "^13.0.0",
    "react-native-paper": "4.9.2"
  }
}

but when importing “react-leaflet” in the App.js file, I have the following error:

react_leaflet error (Unable to resolve module ‘hooks.js’)

Can you help me, thanks.

Mimic Alert function with onclick

i am trying to create alert function with div instead of using alert().
The reason why i want to create my own alert function is because i want to have a custom css. Alert function is call within my async call

for e.g [just using dummy code for an example]
alert() will actually pause my async call till i click okay which i want

await example.then(dataTable => {
 if(condition is true){
  alert('this is alert ')
 }
)}

now i want to mimic the same functionality with alert function using the method below

html code

<div class="alert_box" id="alert_box" style="visibility:hidden;">
    <span class="closebtn" id="closebutton">&times;</span>
    <strong>Error : </strong> Records Exceed 150K Records . Aborting Multi Tab Download
</div>

JavaScript code inside my async call

if(condition is true){
document.getElementById('alert_box').style.visibility = 'visible'
document.getElementById('closebutton').onclick = function(){
console.log("CLICK ME")
document.getElementById('alert_box').style.visibility = 'hidden'
}

I understand that alert is on browser level if im not mistaken but is there a way we can achieve the same result with custom function to mimic alert()?