Align (hover) dropdown menu on small PC screen with parent

I am building my first Gatsby/React project and I want to create a navbar. After creating all the components, I discovered that when I reduce my screen size, my dropdown menu is not aligned with its parent (although it is perfectly aligned on big screens). Among other things, I played with @media screen but nothing seems to work as expected. I think one of the problems is that I want the dropdown menu displayed when I hover over it. Please find attached a complete copy of the Navbar component and CSS file I am using.

Gatsby/React:

import { Link } from "gatsby"
import { FiAlignJustify } from "react-icons/fi"
//import logo from "../assets/images/LIT_logo.jpg"
import { Dropdown, DropdownButton, Nav, NavDropdown } from "react-bootstrap"

const NavBar = () => {
  const [show, setShow] = useState(false)
  // const [logoIsVisible, setLogo] = useState(false)
  const [isHovered, setIsHovered] = useState(false)
  const [isClicked, setIsClicked] = useState(false)

  return (
    <nav className="navbar">
      <div className="nav-center">
        <div className="nav-header">

          <button className="nav-btn" onClick={() => setShow(!show)}>
            <FiAlignJustify />
          </button>
        </div>
        <div className={show ? "nav-links show-links" : "nav-links"}>
          {/*this is the toggle functionality of the nav-btn */}

          <Link
            to="/about"
            className="nav-link"
            activeClassName="active-link"
            onClick={() => setShow(false)} //when you go to another page, the nav drop-down menu closes
          >
            about us
          </Link>
          <Link
            to="/news"
            className="nav-link"
            activeClassName="active-link"
            onClick={() => setShow(false)}
          >
            news
          </Link>
          <Link
            to="/myforms"
            className="nav-link"
            activeClassName="active-link"
            onClick={() => setShow(false)}
          >
            my forms
          </Link>

          <NavDropdown
            id="nav-dropdown-dark-example"
            title="Dropdown"
            onMouseEnter={() => setIsHovered(true)}
            onMouseLeave={() => setIsHovered(false)}
            onToggle={() => setIsClicked(!isClicked)}
            show={isClicked || isHovered}
            className="nav-drop"
          >
            <NavDropdown.Item href="/">English</NavDropdown.Item>
            <NavDropdown.Item href="/">Spanish</NavDropdown.Item>
          </NavDropdown>
        </div>
      </div>
    </nav>
  )
}

export default NavBar

CSS:

*,
::after,
::before {
  box-sizing: border-box;
}

:root {
  /* COLORS  */
  /* primary */
  --primary-0: #f0efff;
  --primary-50: #d8d6ff;
  --primary-100: #c1beff;
  --primary-200: #aaa5ff;
  --primary-300: #938dff;
  --primary-400: #7b74ff;
  /* main */
  --primary-500: #645cff;
  --primary-600: #554ed9;
  --primary-700: #4640b3;
  --primary-800: #37338c;
  --primary-900: #282566;
  --primary-1000: #191740;
  --primary-1100: #0a0919;
  --lit-0: #1e1888;
  /* grey */
  --grey-0: #fafbfc;
  --grey-50: #f2f4f8;
  --grey-100: #eaedf3;
  --grey-200: #e2e7ef;
  --grey-300: #dbe0ea;
  --grey-400: #d3dae6;
  --grey-500: #cbd3e1;
  --grey-600: #adb3bf;
  --grey-700: #8e949e;
  --grey-800: #70747c;
  --grey-900: #51545a;
  --grey-1000: #333538;
  --grey-1100: #141516;

  /* rest */
  --black: #222;
  --white: #fff;
  --red-light: #f8d7da;
  --red-dark: #842029;
  --green-light: #d1e7dd;
  --green-dark: #0f5132;
  /* box shadows */
  --shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-2: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-3: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-4: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  /* typography */
  --defaultFontSize: 87.5%;
  --headingFont: "Inconsolata", monospace;
  --bodyFont: "Montserrat", sans-serif;
  --smallText: 0.8em;
  --extraSmallText: 0.7em;
  /* rest */
  --backgroundColor: var(--grey-0);
  --textColor: var(--grey-1000);
  --borderRadius: 0.25rem;
  --letterSpacing: 1spx;
  --transition: 0.3s ease-in-out all;
  --max-width: 1120px;
  --fixed-width: 600px;
}
html {
  font-size: var(--defaultFontSize);
}
@media only screen and (min-width: 576px) {
  :root {
    --defaultFontSize: 100%;
  }
}
@media only screen and (min-width: 768px) {
  :root {
    --defaultFontSize: 112.5%;
  }
}


body {
  background: var(--backgroundColor);
  color: var(--textColor);
  font-family: var(--bodyFont);
  font-weight: 400;
  line-height: 1.75;
}

p {
  margin: 0;
  margin-bottom: 1rem;
  max-width: 40em;
}

h1,
h2,
h3,
h4,
h5 {
  margin: 0;
  margin-bottom: 1.38rem;
  font-family: var(--headingFont);
  font-weight: 400;
  line-height: 1.3;
  text-transform: capitalize;
  letter-spacing: var(--letterSpacing);
}

h1 {
  font-size: 3.052rem;
}

h2 {
  font-size: 2.441rem;
}

h3 {
  font-size: 1.953rem;
}

h4 {
  font-size: 1.563rem;
}

h5 {
  font-size: 1.25rem;
}

small,
.text-small {
  font-size: var(--smallText);
}

ul {
  padding: 0;
  list-style-type: none;
}
a {
  text-decoration: none;
}
.img {
  width: 100%;
  display: block;
  object-fit: cover;
}
.form {
  width: 100%;
  background: var(--white);
  border-radius: var(--borderRadius);
  box-shadow: var(--shadow-2);
  padding: 2rem 2.5rem;
}
label {
  display: block;
  font-size: var(--smallText);
  margin-bottom: 0.5rem;
  text-transform: capitalize;
}

input,
textarea {
  width: 100%;
  padding: 0.375rem 0.75rem;
  border-radius: var(--borderRadius);
  background: var(--grey-0);
  border-color: transparent;
  border: 1px solid var(--grey-300);
}
.form-row {
  margin-bottom: 1rem;
}
textarea {
  width: 100%;
  height: 7rem;
}

::placeholder {
  color: var(--grey-600);
}
.form-alert {
  color: var(--red-dark);
  font-size: var(--extraSmallText);
  letter-spacing: var(--letterSpacing);
  text-transform: capitalize;
}
hr {
  border-top: var(--line);
}
/*----------------------------------------------------------------------------------------------*/

.dropdown-toggle {
  white-space: nowrap;
  color: #28a745;
}
/* .btn-success {
  color: #fff;
  background-color: #28a745;
  border-color: #28a745;
} */

button.dropdown-toggle {
  background-color: rgb(64, 64, 119);
}

button.dropdown-toggle:hover {
  background-color: rgb(65, 79, 136);
}

.dropdown-toggle:after {
  display: inline-block;
  margin-left: 0.255em;
  vertical-align: 0.255em;
  content: "";
  border-top: 0.3em solid;
  border-right: 0.3em solid transparent;
  border-bottom: 0;
  border-left: 0.3em solid transparent;
}

/* .drop-content {
  display: block;
  position: relative;
  background-color: var(--lit-0);
  margin-left: 20vh;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  padding: 12px 16px;
  z-index: 1;
} */

/* .drop-content {
  margin-left: 50px;
} */

/* Shows dropdown menu */
.dropdown-menu.show {
  display: block;
}

.dropdown-menu {
  position: relative;
  top: 100%;
  left: 0;
  z-index: 1000;
  display: none;
  float: left;
  min-width: 10rem;
  padding: 0.5rem 0;
  font-size: 1rem;
  color: #212529;
  text-align: left;
  list-style: none;
  background-color: var(--lit-0);
  background-clip: padding-box;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0.25rem;
}

/* @media screen and (max-width: 600px) {
  .dropdown-menu {
    left: 50% !important;
    transform: translate(-50%) !important;
  }
} */

/* items in the dropdrown */
.dropdown-item {
  display: block;
  width: 100%;
  padding: 0.25rem 1.5rem;
  clear: both;
  font-weight: 400;
  color: #212529;
  text-align: inherit;
  white-space: nowrap;
  background-color: transparent;
  border: 0;
  color: white;
  text-align: center;
}

.dropdown-item:hover {
  color: var(--primary-500);
}

.nav-drop:hover {
  height: 3.69vh;
}
/* This allow menu to remain open after hovering so we can click links*/

/*----------------------------------------------------------------------*/

button,
.btn {
  cursor: pointer;
  appearance: none;
  color: var(--white);
  background: var(--primary-500);
  border: none;
  border-radius: var(--borderRadius);
  letter-spacing: var(--letterSpacing);
  padding: 0.375rem 0.75rem;
  box-shadow: var(--shadow-1);
  transition: var(--transition);
  text-transform: capitalize;
}
button:hover,
.btn:hover {
  color: var(--white);
  background: var(--primary-700);
  box-shadow: var(--shadow-2);
}
button.small {
  padding: 0.3rem 0.5rem;
  font-size: var(--smallText);
}
button.hipster {
  color: var(--primary-500);
  background: var(--primary-50);
  box-shadow: var(--shadow-1);
}
button.hipster:hover {
  background: var(--primary-100);
  box-shadow: var(--shadow-2);
}
button.block {
  width: 100%;
}

/* Basic Classes */
.alert {
  padding: 0.375rem 0.75rem;
  margin-bottom: 1rem;
  border-color: transparent;
  border-radius: var(--borderRadius);
}

.alert-success {
  color: var(--green-dark);
  background-color: var(--green-light);
}
.alert-danger {
  color: var(--red-dark);
  background-color: var(--red-light);
}

.container {
  padding: 5rem 0;
}
.container-center {
  width: 90vw;
  max-width: var(--max-width);
  margin: 0 auto;
}
.page {
  width: 90vw;
  max-width: var(--max-width);
  margin: 0 auto; /* auto keeps the 90% of the page specified in the width at the center of the page */
}
.page {
  min-height: calc(100vh - (6rem + 4rem));
}

.title {
  text-align: center;
  margin-bottom: 2rem;
}
.title-underline {
  height: 0.2rem;
  width: 7rem;
  background: var(--primary-600);
  margin: 0 auto;
}

form > *:last-child {
  margin-bottom: 0;
}

/* loading */
@keyframes spinner {
  to {
    transform: rotate(360deg);
  }
}

.loading {
  width: 6rem;
  height: 6rem;
  border-radius: 50%;
  border: 3px solid #ccc;
  border-top-color: var(--clr-primary-5);
  animation: spinner 0.6s linear infinite;
}
.loading {
  margin: 0 auto;
}
/* form loading */

.form-loading {
  position: relative;
}
.form-loading::before {
  background: var(--white);
  position: absolute;
  content: "";
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  border-radius: var(--borderRadius);
  opacity: 0.8;
}
@keyframes spinner {
  to {
    transform: rotate(360deg);
  }
}

.form-loading::after {
  content: "";
  position: absolute;
  top: calc(50% - 3rem);
  left: calc(50% - 3rem);
  width: 6rem;
  height: 6rem;
  border-radius: 50%;
  border: 3px solid #ccc;
  border-top-color: var(--clr-primary-5);
  animation: spinner 0.6s linear infinite;
}

/*#########*/
/* END OF GLOBALS */
/*#########*/

/*#########*/
/* Navbar */
/*#########*/
.navbar {
  /* parent container */
  width: 100%;
  display: flex;
  align-items: center; /* Both this and the line below it were center. However I liked it more when everything was aligned left */
  justify-content: center;
  background: #1e1888;
}

/*sits in the center of the navbar */
.nav-center {
  width: 90vw; /* 90% of the screen width regardless if small or big */
  max-width: 100%; /*var(--max-width); our content is never going to be bigger that max width */
  /* make the nav-center span all the way accross the navbar so that contact button is all the way to the right*/
}
/* */
.nav-header {
  height: 6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-header img {
  width: 80px;
  margin-left: -6px;
  margin-bottom: -9px;
  justify-content: flex-start;
}

.nav-btn {
  padding: 0.15rem 0.75rem;
}
.nav-btn svg {
  font-size: 1.5rem;
}
.nav-links {
  height: 0; /*hide by default */
  overflow: hidden; /*when overflow, hide them */
  display: flex;
  flex-direction: column; /*one on top of each other */
  transition: var(--transition);
}

/* change here if you add more links, this makes navbar bigger */
.show-links {
  height: 29rem;
}
/* Individual links*/
.nav-link {
  display: block;
  text-align: center;
  font-size: 1.5rem;
  text-transform: capitalize;
  color: white;
  letter-spacing: var(--letterSpacing);
  padding: 1rem 0;
  border-top: 1px solid var(--grey-500);
  transition: var(--transition);
}

.nav-link:hover {
  color: var(--primary-500);
}

.active-link {
  color: var(--primary-500);
}
.contact-link {
  display: flex;
  justify-content: center;
}
.contact-link a {
  padding: 0.15rem 1rem;
}
/* Logo on navbar will get reduced to 50px when less than 600px screen */
@media screen and (max-width: 600px) {
  .nav-header img {
    width: 50px;
  }
}
/* Logo on navbar will dissapear when smaller than 300px screen is used */
@media screen and (max-width: 300px) {
  .nav-header img {
    display: none;
  }
}
/*All these will apply once the screen is BIGGER than 992px */
@media screen and (min-width: 650px) {
  .navbar {
    height: 6rem;
  }
  .nav-center {
    display: flex; /* all in one line */
    align-items: center; /* align vertically in the center*/
  }
  .nav-header {
    padding: 0;
    margin-right: 2rem;
    height: auto; /*show them in big screen */
  }

  .nav-btn {
    /* this hides the nav-button once we get to the bigg screen (past 992px) */
    display: none;
  }

  .nav-btn:hover {
    display: block;
  }

  /* margin auto allows for the links to shrink as the screen shrinks */
  .nav-links {
    margin-left: auto;
    margin-right: auto;
    height: auto !important; /* once we go to big screen we see the links*/
    flex-direction: row; /* now align them as a row*/
    align-items: center; /* align vertically in center*/
    width: 100%; /* make the links span all across*/
    justify-content: flex-end;
  }
  .nav-link {
    padding: 0;
    border-top: none;
    margin-right: 1rem;
    font-size: 1rem;
  }
  .contact-link {
    width: 100%;
    justify-content: flex-end;
    align-items: center;
    margin-right: 0;
    margin-left: auto;
  }
}
/* 
.dropdown-btn {
  display: block;
} */

/*#########*/
/* Footer */
/*#########*/
.page-footer {
  text-align: center;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center; /* change this to move it left and right */
  background: var(--black);
  color: var(--white);
}
.page-footer h5 {
  margin-bottom: 0;
}
.page-footer p {
  margin-bottom: 0;
}
.page-footer span,
.page-footer a {
  color: var(--primary-500);
}

/*#########*/
/* Error */
/*#########*/
.error-page {
  min-height: calc(100vh - (6rem + 4rem));
  text-align: center;
  padding-top: 3rem;
}
.error-page h1 {
  font-size: 9rem;
}

/*#########*/
/* Contact */
/*#########*/

.contact-page {
  display: grid;
  gap: 2rem 3rem;
  padding-bottom: 3rem;
}
@media screen and (min-width: 992px) {
  .contact-page {
    grid-template-columns: 1fr 1fr;
    align-items: center;
  }
}
/*#########*/
/* About */
/*#########*/

.about-page h2 {
  text-transform: none;
  font-weight: bold;
}
.about-page {
  display: grid;
  gap: 2rem 4rem;
  padding-bottom: 3rem;
}
.about-img {
  border-radius: var(--borderRadius);
  height: 500px;
} /* 500px for the SMALL screen */

@media screen and (min-width: 992px) {
  .about-page {
    grid-template-columns: 1fr 1fr; /*Since the parent (about-page) is a grid, once the page gets big enough, we set it to 2 columns layout*/
    align-items: center;
    height: 400px;
  }
  .about-img {
    height: 100%; /* set your height based on your parent (about-page), 100% of the parent */
  }
}

.featured-recipes > h5 {
  text-align: center;
  max-width: 100%;
}
/*#########*/
/* Hero */
/*#########*/

.hero-img {
  height: 100%; /* 100% of the size of the parent (hero), using parent to control size of the image*/
  border-radius: var(--borderRadius);
}
.hero {
  height: 40vh; /* 40% of the size of the window*/
  position: relative;
  margin-bottom: 2rem;
}
.hero-container {
  position: absolute; /* This positions text ON TOP of the image*/
  top: 0;
  left: 0;
  width: 100%;
  height: 100%; /* also 100% of the parent (hero same as in hero-img). That is why text and image are perfectly aligned on top of each other*/
  display: flex;
  align-items: center; /* we just put the text in the center and use absolute potition*/
  justify-content: center;
  background: rgba(0, 0, 0, 0.4); /* makes the background a bit darker*/
  border-radius: var(--borderRadius);
}
.hero-text {
  color: var(--white);
  text-align: center;
}

@media only screen and (min-width: 768px) {
  .hero-text h1 {
    font-size: 4rem;
    margin-bottom: 0;
  }
}

Imitate click with jQuery to get filtered multigallery by URL

I have website, created with Elementor. Website belongs to photographer. He has got there an Elementor Multigallery, with filter at the top. I need to create external links, which can bring you to the subpage and directly show only filtered items.

Here’s the link to multigal: https://chosephoto.com/photo/

I need to do something like that, when I enter the https://chosephoto.com/photo/#fashion I will received the current subpage, but it will shows only images from gallery “fashion”. Not all images.

I thought about imitating jQuery click by query string (get the value of /#….) and then do the jquery click the with attribute, which equals the value in query string, However I even don’t know, how can I do it with jQuery. I am jQuery beginner.

Thank you for a help.

‘BackgroundCheck’ with ‘Swiper touch slider’

There are two js plugins that I’m using. One is “BackgroundCheck – http://www.kennethcachia.com/background-check/cross-origin.html” which works with jquery to detect background contrast and based on that applies black/white color to elements, and the other one is “Swiper touch slider – https://swiperjs.com”. Both are well-known plugins in their respective categories.

The code below initiates the Swipder slider:

const swiper = new Swiper('.swiper', {

  direction: 'vertical',
  loop: true,

  pagination: {
    el: '.swiper-pagination',
  },

  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },

  scrollbar: {
    el: '.swiper-scrollbar',
  },
});

All I want is that when every time a slide is swiped or any navigation/pagination element is clicked, the BackgroundCheck plugin is initiated/refreshed:

BackgroundCheck.refresh(); 

You can see the BackgroundCheck in action on a different slider here: http://www.kennethcachia.com/background-check/slider.html

I want to emulate the functionality with the Swiper slider. I just can’t make it work as JS is not my forte and I’m kinda stuck here.

Trying to understand underscore’s invoke

So there is this function by undersore.js, called invoke:

`_.invoke = function(obj, method) {     
  var args = slice.call(arguments, 2);
  var isFunc = _.isFunction(method);
  return _.map(obj, function(value) {      
    var func = isFunc ? method : value[method];       
    return func == null ? func : func.apply(value, args);
  });
};`

It gets an object, and a method (string) and returns an array of values of having applied such method to the object, for example:

`_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
 => [[1, 5, 7], [1, 2, 3]]`

My porblem is that, while I understand that to avoid having the error ‘method is not a function’ since initially it is a string, you have to somehow change it to a valid method format, I don’t understand how value[method] achieves this.

TL;DR: I don’t understand the value[method] syntax, not clear what it does.

I’m trying to do an implementation of Underscore.js and haven’t figured out how to implement the invoke function yet.

Large file downloads don’t work in Firefox browser

I have a Angular app where users can download some documents(.jpg, .mp4 and .pdf) that they uploaded. Basically the download of the file works in this way: A service is called which returns some information about the file as name, type, size and the content of it in base64.

This is the download method in Component when the user clicks on the download button:

downloadDocument(doc: Document) {
  this._subDownDocument = this.service.getDocument(doc).subscribe((resp: Document) => {
    var link = document.createElement("a");
    link.download = resp.fileName;
    link.target = "_blank";

    // Construct the URI
    link.href = resp.url;//Url is the content of the file in base64
    document.body.appendChild(link);
    link.click();

    // Cleanup the DOM
    document.body.removeChild(link);
  });
}

It’s working perfectly for files up to 12mb. But when files are bigger the download doesn’t start, the service brings the file correctly but I don’t know why the download doesn’t start. No error is shown in the browser console.

This problem only happens with Firefox because in Google Chrome it works fine. Any idea on how can I solve this?

How to display json using pre tag in angularjs

I want to display the JSON response inside div using ng-repeat. How can I show that JSON in a formatted way?
My code –

<div class="card" ng-repeat="data in finalJson.data">
   <div class="card-body">
   <pre>{{data.json | json}}</pre>
    </div>
</div>
    
 $scope.getJSON=()=>{
  var settings = {
  "url": "https://api/json,
  "method": "GET",
  "timeout": 0,
   };
    
   $.ajax(settings).done(function (response) {
   console.log("response",response);
   $scope.finalJson = response;
   $scope.$apply();
   }).fail(function (error){
       console.log(error);
   });
   }
  }

From this approach I am getting output like –
enter image description here

I want to make something like JSON viewer. How can I do this in angularjs please help

Why is div with a id is not a node? [duplicate]

I am trying to understand why I am getting the following error

Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.

I was under impression that the DOM hasn’t been populated when the script run but I delayed it with timeout but still I get the error

window.setTimeout(()=>{
          let callback = function(e){
            console.log(e)
          }
          let mutations = new MutationObserver(callback);
  
          mutations.observe(document.querySelectorAll('#app-container'), {
           childList: true, subtree: true 
          })
        },5000)

From the way, I know it that any div with a valid id or class is a Node? I am new to observable but I get that node error, in general, a lot. I know the MDN has the definition but I want to understand in layman’s terms what is Node and why I get this error

enter image description here

React `act` warning on DidMount and Promise

Okay so I have this bunch of code that’s is thrown on useEffect(() => {...}, []) a.k.a componentDidMount.

// utils/apiCalls.ts

export const loadData = async <T>(
  url: string,
  errorMsg = "Couldn't retrieve data.",
): Promise<T> => {
  const res = await fetch(url, { mode: 'cors', credentials: 'include' });
  if (res.ok) return await res.json();
  throw new Error(errorMsg);
};

export const loadChat = (id: number): Promise<IChat> => {
  return loadData<IChat>(
    `${CHAT_API}/${id}/nested/`,
    "We couldn't get the chat.",
  );
};
// components/MessageContainer.tsx

const MessageContainer = (/* props */) => {
  /*
   * Some coding...
   */

  useEffect(() => {
  if (session === null) return;
  if (chat === null) {
    loadChat(session.chat).then(setChat).catch(alert);
    return;
  }
  // More coding...
}, [session, chat]);
};

The problem comes when I try to test it with @testing-library/react since it gives me this warning Warning: An update to MessagesContainer inside a test was not wrapped in act(...).

How can I make a correct test for this?
Here’s the test I have right now.

// tests/MessagesContainer.spec.tsx

describe('MessagesContainer suite', () => {
  it('loads messages on mount', () => {
    fetchMock.mockResponseOnce(JSON.stringify(ChatMock));
    render(
      <SessionContext.Provider value={SessionMock}>
        <MessagesContainer {...MessagesContainerMockedProps} />
      </SessionContext.Provider>,
    );

    expect(fetchMock.mock.calls.length).toEqual(1);
  });
});

NOTE: Wrapping render on act did not work.

How to dynamically calculate an end date?

I’m new here, in the sense that this is the first question I ask.

I have a reservation component comprising, among other things, three selectors: a first datepicker to indicate the start date of the reservation, a selector with pre-defined reservation durations and a second datepicker which must indicate the end date of the reservation.

When the first datepicker indicates a date and the reservation duration selector has a selected value (for example 1 hour of rental), the second datepicker must automatically display the correct date and time of the end.

Do you have any idea how I can do this in javascript? I specify that the project is based on VueJS2 and the datepicker is vue2-datepicker.

Thank you for help me !

I specify that I am new to algorithms, so I do not know a solution to my problem. I only want to learn.

Nuxt.js cannot update head() properties from asyncData()

I created a server-side rendered Vue.js blog using Nuxt.js with Typescript and Ghost but I’m having some issues to update html metatag using data from asyncData().

From Nuxt.js documentation I know that asyncData() is called every time before loading page components and merges with component data.

I’m getting this error:

Property ‘title’ does not exist on type ‘{ asyncData({ app, params }: Context): Promise<{ title: string | undefined; excerpt: string | undefined; feature_image: Nullable | undefined; html: Nullable | undefined; }>; head(): any; }’.

This is my code:

<script lang="ts">
import { Context } from '@nuxt/types'
import { PostOrPage } from 'tryghost__content-api'

export default {
  async asyncData ({ app, params }: Context) {
    const post: PostOrPage = await app.$ghost.posts.read(
      {
        slug: params.slug
      },
      { include: 'tags' }
    )

    return {
      title: post.title,
      excerpt: post.excerpt,
      feature_image: post.feature_image,
      html: post.html
    }
  },

  head () {
    return {
      title: this.title,
      meta: [
        {
          hid: 'description',
          name: 'description',
          content: this.excerpt
        }
      ]
    }
  }
}
</script>

I already tried some solutions like using data() to set a default value for each item but nothing. Do you have any suggestion?

Pass vue component to function

I am working on porting a project over to vue. I’m using muuri for a layout manager. However i need to use

grid.add(itemElem, {
  layout: false,
  active: false
});

itemElem was an html element i created with document.createElement but that is a component now. How do i pass a component to the function?

I tried

grid.add(<MyComponent />, {
  layout: false,
  active: false
});

However that doesn’t work

I am using vue3 with options API

Set a Default current Datetime in datetime-local using Angularjs

I am new to HTML. I am stuck in a very simple problem. I am using datetime-local input type in a web application.
I just want to define a default current value for the datetime. Any ideas

HTML Code
<input type=”datetime-local” value=”row.ActivityDate” ng-disabled=”row.chkDateTime == false” ej-datetimepicker ng-init=”row.ActivityDate=”” ng-model=”row.ActivityDate” class=”form-control date”
id=”ptDateTimePicker{{$index}}” ng-required=”true” ng-change=”ejDTonChange(row.ActivityDate, $index)”>

im try to insert some queris but i want shows in html

Persisting Error – “Parse Error: Header overflow”

I am working on a Next.js project, in which I have included a login system with NextAuth.

Everything was working fine at the beginning, but recently I keep getting an error every time I try to get the session.

The Error:
https://pastebin.com/Mh624N3c

StackOverflow doesn’t let me post the whole error, so I had to use Pastebin.

This is the first time I encounter such an error, and I can’t seem to be able to find a solution. I am using JWT as the session strategy, if that has to do anything with the issue.

This is the code I use for handling the authentication & session:

await NextAuth(req, res, {
        adapter: MongoDBAdapter(clientPromise),
        pages: {
            signIn: "/login"
        },
        providers: [
            CredentialsProvider({
                name: "credentials",
                credentials: {
                    email: { label: "Email", type: "email", placeholder: "[email protected]" },
                    password: { label: "Password", type: "password" }
                },
                async authorize(credentials, req) {
                    const account = await Accounts.exists(credentials.email)
                    const cryptr = new Cryptr(Config.secret)
                    const encEmail = cryptr.encrypt(credentials.email)
                    const url = process.env.NODE_ENV == "development" ? "http://localhost:3000/" : Config.url
                    
                    if (account) {
                        const password = cryptr.decrypt(account.password)
                        if (credentials.password == password) {
                            return {
                                ...account,
                                _id: null
                            }
                        } else {
                            return res.redirect("/login?error=true")
                        }
                    } else {
                        const code = await Accounts.requestVerification(credentials.email, password)

                        const message = {
                            to: credentials.email,
                            from: "[email protected]",
                            subject: "BytesToBits API - Create Your Account",
                            html: emailStyle(credentials?.email, url, code),
                        }

                        SendGrid.send(message).then(() => console.log("Email Sent"))

                        return res.redirect("/verify?email=" + encEmail)
                    }
                }
            })
        ],
        jwt: {
            secret: Config.secret,
            encryption: true
        },
        secret: Config.secret,
        session: {
            strategy: "jwt"
        },
        callbacks: {
            async jwt({ token, user }) {
                if (user) {
                    token.user = user
                }

                return token
            },
            async session({ session, token }) {

                let data = token.user

                if (data) {
                    if (await Accounts.exists(data.email)) {
                        data.token = await Accounts.getToken(data.email)
                    }
                    data.tokenInfo = await Accounts.tokenInfo(data.token)
                }

                return data
            }
        }
    })

This happens every time I try to fetch the session or authenticate.

When the user authenticates, a session must be formed, which can be fetched from the client for usage. However, whenever I try to authenticate of fetch the session, a “Parse Error: Header overflow” occurs.

WordPress WP Media is not working – this.options is undefined

I’m using wp media to upload image using Javascript.

JS Part is here –

handleLogoUpload () {
  var self = this;

  // If the media frame already exists, reopen it.
  if ( this.wpmedia ) {
      this.wpmedia.open();
      return;
  }

  // Create a new media frame
  this.wpmedia = wp.media({
     title: __( 'Select or Upload Media Of Your Chosen Persuasion' ),
     button: {
        text: __( 'Use this media' )
     },
     type : 'image',
     multiple: false
  });

  this.wpmedia.on( 'select', function() {
       // Handle this in my way
  });

  this.wpmedia.open();
},

I’ve also enqueued the Media library in PHP end.

But when, I just choose an image from Local directory to Upload Getting this error –

Uncaught TypeError: this.options is undefined
createAttachmentView http://wpex.test/wp-includes/js/media-views.js?ver=5.9.2:9336

Error Demo in Console

It seems error in media-views.js.

Is there anyone have faced this before.

javascript homework Even and odd

Write the function sudaLicha which

It will accept 1 argument – max. Number.
It will return numbers from 1 to the specified maximum with information on whether the number is even or odd, so e.g.
sudaLicha (5); this long string is returned:

Number 1 is odd
Number 2 is even
Number 3 is odd
Number 4 is even
Number 5 is odd
Number 1 is odd
Number 2 is even
Number 3 is odd
Number 4 is even
Number 5 is odd
You can assume that the input is a number, you don’t have to test meaningless values
However, if the number is small (less than 1), return an empty string
To separate a sequence of lines n added to the end of each line
Use the% (modulo) operator to calculate even / odd
If you can handle the solution with a loop, try it with while and vice versa – both are possible and fine.

I need help with this task