SwiperJS css animation disable swipe function

I want to add some animation to swiperjs to tell user this slider has swipe function and you can swipe to slide, animation working good but it conflict with swiperjs default swiping function, and you can not swipe slides, is there any solution to fix this?

var swiper = new Swiper(".mySwiper", {
  slidesPerView: 3,
});
.swiper-wrapper {
  transition-duration: 0ms;
  transform: translate3d(0px, 0px, 0px);
  animation: example 5s infinite alternate;
}

@keyframes example {
  0% {
  transform: translate3d(0px, 0px, 0px);
  }
  50% {
  transform: translate3d(0px, 0px, 0px);
  }
  75% {
  transform: translate3d(-20px, 0px, 0px);
  }
  100% {
  transform: translate3d(0px, 0px, 0px);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>

<div class="swiper mySwiper">
  <div class="swiper-wrapper">
    <div class="swiper-slide">Slide 1</div>
    <div class="swiper-slide">Slide 2</div>
    <div class="swiper-slide">Slide 3</div>
    <div class="swiper-slide">Slide 4</div>
    <div class="swiper-slide">Slide 5</div>
    <div class="swiper-slide">Slide 6</div>
    <div class="swiper-slide">Slide 7</div>
    <div class="swiper-slide">Slide 8</div>
    <div class="swiper-slide">Slide 9</div>
  </div>
</div>

React – clearing email input field, after form submission

After the form is submitted, the password field input is emptied, but not the email input field.

As you can see in the HandleSubmit function:
ref.current.value = “”; is what I’ve used as an attempt to clear the input fields after form submission, but it is only working for the password input field.

I’ve looked at a few other answers on SO, and I’ve tried e.target.reset(), and I’ve also tried setField(“”); with no luck yet yet.


import React from 'react';
import Form from 'react-bootstrap/Form';
import { Button } from 'react-bootstrap';
import { Container } from 'react-bootstrap';
import { useState } from 'react';
import { useRef } from 'react';

const allThis = () => {
  const [form, setForm] = useState({})
  const [errors, setErrors] = useState({})

  const setField = (field, value) => {
    setForm({
      ...form,
      [field]: value
    })
    // Check and see if errors exist, and remove them from the error object:
    if (!!errors[field]) setErrors({
      ...errors,
      [field]: null
    })
  }

  const ref = useRef(null); // set up empty field

  const handleSubmit = (e) => {
    e.preventDefault();
    const newErrors = findFormErrors()
    if (Object.keys(newErrors).length > 0) {
      setErrors(newErrors)
    } else {
      alert('Thank you for your feedback!');
      ref.current.value = ""; // empty the field
    }
  }

  const findFormErrors = () => {
    const { email, password } = form
    const newErrors = {};
    if (!email || email === '') newErrors.email = 'cannot be blank!';
    /* else if (email.length > 30) newErrors.email = 'email is too long!'; */
    if (!password || password === " ") newErrors.password = "cannot be blank";
    return newErrors
  }

  return (
    <Container>
      <Form className="reduceForm">
        <Form.Label className="contact">Contact Me</Form.Label>
        <Form.Group className="mb-3" controlId="formBasicEmail">
          <Form.Label>Email address</Form.Label>
          <Form.Control input ref={ref} type="email" placeholder="Enter email"  
            onChange={e => setField('email', e.target.value)}
            isInvalid={!!errors.email} />
          <Form.Control.Feedback type='invalid'>
            {errors.email}
          </Form.Control.Feedback>
        </Form.Group>

        <Form.Group className="mb-3" controlId="formBasicPassword">
          <Form.Label>Password</Form.Label>
          <Form.Control input ref={ref} type="password" placeholder="Password"
            onChange={e => setField('password', e.target.value)}
            isInvalid={!!errors.password} />
          <Form.Control.Feedback type='invalid'>
            {errors.password}
          </Form.Control.Feedback>
        </Form.Group>
        <Button onClick={handleSubmit} variant="primary" type="submit">
          Submit
        </Button>
      </Form>
    </Container>
  )

}

export default allThis

Determine if two non-rectangles overlap in JS

I have two html elements (in my case they are SVG path elements). Each of these has a different stroke width. Is there any way to determine if two of these paths overlap? I have tried using the npm path intersection library, but it doesn’t allow me to specify a width. Also, the results are approximate, but I need more exact data.

I don’t need to calculate the actual intersection area, or coordinates. I just need to know if an intersection occurs between these two paths with definite widths. Is there a solution?

How to use a google sheet as a database stored in the User’s google drive

I want to build an app where the data of the user is stored in their own google Drive. I am currently using json files stored in the drive but is it possible for me to use a spreadsheet stored in the user’s drive having all the data. I have read articles online which go on to make a public database but I want a private one stored in the user’s drive.

Do you think this approach would be better, if yes then how could I go about implementing it?

PS I am using react-native

Drawing on more than one Easel.JS canvas on a page

I am trying to create a drawing game that has multiple canvases on the same page. I tried many different ways but Easel was the easiest. I am open to other options if this is not possible with Easel.

I really just don’t know where to start. The first canvas works but when I add a second one and change all the variables to different names (stage -> stage2), it still won’t draw on the second canvas. I have tried to create it to one function and pass the canvas ID as the parameter so it runs the drawing function for each canvas but that doesn’t work either.

Anything helps. Thank you!

Creating tabs using javascript

I have created tabs using Html for two files one is Fontend other end is backend(data stored in mySql database) that means whenever users puts the data in the frontend and can see data in other tab Now I want to create tabs using JavaScript, How can this do? I searched but i didn’t find.Please Help

<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <style>
    body {
      font-family: Arial;
    }
    /* Style the tab */
    
    .tab {
      overflow: hidden;
      border: 3px solid #ccc;
      background-color: #f1f1f1;
      tab-size: 6;
    }
    /* Fade in tabs */
    
    @-webkit-keyframes fadeEffect {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }
    
    @keyframes fadeEffect {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }
    
    ul {
      list-style-type: none;
      margin: 50px;
      padding: 0;
      overflow: hidden;
    }
    
    li {
      float: left;
    }
    
    li a {
      display: block;
      padding: 15px;
      background-color: lightblue;
    }
  </style>
</head>

<body>



  <div id="links">
    <ul>
      <li><a href="students2.html">Students Details Page FronEnd</a></li>
      <li><a href="student_getdata.html">Students Details BackEnd</a></li>
    </ul>
  </div>

  <div id="content"></div>

  <script>
    $(function() {
      $("#links > ul li a").click(function(e) {
        e.preventDefault(); //so the browser doesn't follow the link

        $("#content").load(this.href, function() {
          // alert("loaded");
        });
      });
    });
  </script>

</body>

</html>

Why isAuthenticated return false in passport.js local strategy after successful login the user

I have the following code to authenticate through the passport-local strategy:

    
routes.post("/login", passport.authenticate("local"), (req, res) => {
  res.json(req.user);
});

function ensureAuth(req, res, next) {
  console.log(req.isAuthenticated());
  if (req.isAuthenticated()) {
    next();
  } else {
    req.flash("info", "You must be logged in to see this page");
    res.redirect("/login");
  }
}

routes.get("/edit", ensureAuth, (req, res) => {
  res.sendStatus(200);
});

routes.post("/edit", ensureAuth, (req, res, next) => {
  req.user.username = req.body.username;
  req.user.bio = req.body.bio;
  req.user.email = req.body.email;

  req.user.save((err) => {
    if (err) {
      return next(err);
    } else {
      res.send({
        success: "true",
        info: "Profile updated",
      });
    }
  });
});

I can’t figure out why this is happening? Why won’t it authenticate?

Cypress how to test search box and search results

I am trying to test a search box and verify the results that are generated from the search.
Can someone please suggest combinations of search I can try and then how do i verify search results match or count the number of search results returned?

I am new to Cypress so any input and guidance would be helpful.

enter image description here

enter image description here

In Javascript, how do you dynamically add a method to an existing object when the method you want to add uses the “super” keyword in its body?

Suppose you want to add a method f() to a an object myObj where f() uses the “super” keyword in its body. Eg:

function f() {
    return super.foo() + 10
}

myObj.foo = f

Well, this doesn’t work, because f() can’t be declared (since “super” isn’t bound to anything).

Is there a way to dynamically add a method to an object when the method uses the “super” keyword in the method body?

chained await in class chained methods

context: Two javascript classes in separate files, each integrating a different external service and being called in a express.js router.

See “problematic code” below:

  • route
routes.post('/aws', upload.single('file'), async (req, res) => {
    const transcribeParams = JSON.parse(req.body.options)
    const bucket = 'bucket-name'

    const data = await ( await ( await awsTranscribe.Upload(req.file, bucket)).CreateJob(transcribeParams)).GetJob()

    res.send(data) 
})  

  • S3 class
class AmazonS3 {
    constructor() {
        this.Upload = this.Upload
    }

    async Upload(file, bucket) {
        const uploadParams = {
            Bucket: bucket,
            Body: fs.createReadStream(file.path),
            Key: file.filename,
        }

        this.data = await s3.upload(uploadParams).promise()

        return this
    }
}  

  • Transcribe class
class Transcribe extends AwsS3 {
    constructor() {
        super()
        this.CreateJob = this.CreateJob
        this.GetJob = this.GetJob
    }

    async CreateJob(params) {
        if(this.data?.Location) {
            params.Media = { ...params.Media, MediaFileUri: this.data.Location }
        }

        this.data = await transcribeService.startTranscriptionJob(params).promise()

        return this
    }

    async GetJob(jobName) {
        if(this.data?.TranscriptionJob?.TranscriptionJobName) {
            jobName = this.data.TranscriptionJob.TranscriptionJobName
        }

        this.data = await transcribeService.getTranscriptionJob({TranscriptionJobName: jobName}).promise()

        return this
    }
}

problem: the problem is with the chained awaits in the router file:
await ( await ( await awsTranscribe.Upload...
Yes, it does work, but it would be horrible for another person to maintain this code in the future.
How can i make so it would be just
awsTranscribe.Upload(req.file, bucket).CreateJob(transcribeParams).GetJob() without the .then?

PS: For those wondering why the last code is in quotes, it was accusing it of not properly formatted code.

How to set the multiple same name query in javascript ajax

I have python api which can get the multiple data in same query such as.

createdata?ob=120&st=cool&st=warm

It can get st as ["cool","warm"] in python.

st = request.query_params.getlist("st")

print(st) #["cool","warm"] get the data as array.

Now I want to do the same thing from ajax

I try this

$.ajax({
      type: "POST",
      url: "defapp/createdata",
      method: "GET",
      data: {"ob":130,"st":"warm","st":"cool"},
      contentType: "application/json",

and this.

$.ajax({
      type: "POST",
      url: "defapp/createdata",
      method: "GET",
      data: {"ob":130,"st":["warm","cool"]},
      contentType: "application/json",

However former one get ["cool"] as st

later one get [] as st.

how to Using different versions of jQuery and jQuery UI together

I have worked the jQuery and jQuery UI with different version, I just using jQuery UI drag the element in mobile view that normally works fine but they have conflict issue

 _jQuery version ->3.6.0_ `<script src="../resources/vendors/jquery/jquery-3.6.0.min.js"></script>`
_jQuery  UI version ->1.13.1_  `<script src="../resources/vendors/jquery/jquery_UI/jquery-ui.min.js"></script>`

they have conflict the jquery.min.js

error:

 [Intervention] Ignored attempt to cancel a touchmove event with cancelable=false, for example, because scrolling is in progress and cannot be interrupted.

 [Intervention] Ignored attempt to cancel a touchstart event with cancelable=false, for example, because scrolling is in progress and cannot be interrupted.
 
 [Intervention] Ignored attempt to cancel a touchend event with cancelable=false, for example, because scrolling is in progress and cannot be interrupted.
 

How to Using different versions of jQuery and jQuery UI together?

How can I make my Django API only accept requests that come from my website itself?

I had to create an API for my Django application for something sensitive that I couldn’t have in a public and static Javascript file. How can I make it so that this view only accepts requests coming from my own website, and reject any from the “outside” (if someone copied my request below they should get an error)?

If there are any other security concerns please do mention them in your response. My website is hosted on Heroku.

The request in my javascript file:

var clientSecret = await fetch('https://url.com/api/', {
    method: 'POST',
    body: params,
    headers: {
        'Content-Type': 'text/plain'
      },
}).then(r => r.json())

My view for my API (https://url.com/api/):

from rest_framework.request import Request as RESTRequest
from rest_framework.response import Response
from rest_framework.decorators import api_view
import requests

@api_view(['POST'])
def payment(request, *args, **kwargs):
    ... #define headers_in and params_in here
    response = requests.post('https://outboundapirequest.com/v1/request', 
            headers=headers_in,
            data=params_in)

    return Response(response.json()['value'])