Form validation where only one field has to be filled

I’m having trouble in my react app. I have a form that among other things, has fields for an email address and a phone number. These are contact fields, so I would only need one of them to be filled. This has already done by my backend team member on the project, but I want to display an error: “You have to enter at least the email or the phone number” when none of the 2 fields have any input, but if it has either one, I want it to go through. Could this be done in YUP since I am already using it for other types of form validation?

Opnening a new tab in R, capture response, close the tab

so i am building a R shiny Application, that needs a kind of E-Signature,
so i created all my saml encoding, decoding, and the saml requests are structured properly, but whenever i send them as GET requests using httr, it give me 401 status code, so instead i tried to force js to open a new tab and go to the url having the saml request, using the following code,

js_code <- "
shinyjs.Browse = function(url) {
window.open(url,'_blank');
}
"

And then calling
js$Browse(My_Saml_URL)

and it works fine, but I cannot capture the SAML response, as the request is not send from my backend,
So is there any way i can send a request like a browser, would Rselenium work in that case?

In Google Appscripts (javascript), How do you change the Text Color?

I’m trying to change the text color of the “answers” of the following Google App script to Red.

 aText[DocumentApp.Attribute.FOREGROUND_COLOR] = "#FFFF00"

  questions =  sheet.getRange('A1:A30').getValues(); 
  answers = sheet.getRange('B1:B30').getValues(); 

box=[]
for (var q=0;q < questions[0].length ;q++ ) {

  box.push( (q+1) +".  " + questions[0][q] + "nn")  
  box.push(answers[0][q] + "nn" ) //HOW TO CHANGE THE COLOR TO RED
 }

body.replaceText('{{questions}}', box);

AWS : Cannot find module ‘express-fileUpload’ in ubuntu 22.04

this is my package json file :

NU nano 6.2 package.json { "name": "e-commerce", "version": "0.0.0", "private": true, "scripts": { "start": "nodemon ./bin/www" }, "dependencies": { "2": "^3.0.0", "bcrypt": "^5.0.1", "bootstrap-icons": "^1.8.1", "cookie-parser": "~1.4.4", "debug": "~2.6.9", "dotenv": "^16.0.1", "express": "~4.16.1", "express-fileupload": "^1.3.1", "express-handlebars": "^6.0.4", "express-session": "^1.17.2", "hbs": "^4.2.0", "http-errors": "~1.6.3", "moment": "^2.29.3", "mongodb": "^4.5.0", "morgan": "~1.9.1", "nodemon": "^2.0.15", "paypal-rest-sdk": "^1.8.1", "razorpay": "^2.8.1", "referral-code-generator": "^1.0.8", "sweetalert": "^2.1.2", "twilio": "^3.76.1" } }

itemPressed.hasOwnProperty(itemid).splice is not a function. itemPressed.hasOwnProperty(itemid).splice’ is undefined

I’m trying to remove the element that was clicked on, but I get an error. Any idea how to fix it?

  const [itemPressed, setItemPressed] = useState({});
    const changeColor = (itemid) => {
    if(itemPressed.hasOwnProperty(itemid)){
      setItemPressed(itemPressed.splice(itemPressed.hasOwnProperty(itemid), 1))
    }
    else{
    setItemPressed({[itemid]: true, ...itemPressed});
  }}
style={{backgroundColor: itemPressed.hasOwnProperty(item.id) ? '#8b0000': '#ffc6c4'}}>

how can i make vs-code auto-completes paths (parses) if i use ‘@ => ./src/component’ for example in vite project

in a vite project my config file is as follow


import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

export default defineConfig({
  plugins: [vue()],

  build: {
    outDir: 'public',
  },

  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src/components'),
      '~': path.resolve(__dirname, './src'),
    },
  },

  envDir: './',
  envPrefix: 'STO_',
});


vs-code doesn’t parse paths starting with @ or ~ so if a file doesn’t exists i don’t even see the error, and i have bad auto-completion experience

in phpStorm i think there is a file called phpstorm.config.js where we can tell editor how to parse such characters

System.config({
  paths: {
    '@/*': './src/components/*',
    '~/*': './src/*',
  },
});

how can i fix this please in vs-code, is there a similar approach

thanks in advance.

Access Value Returning from Query in Nodejs

I have written a query as follows:

connection.query("SELECT COUNT(*) as count FROM raw_data WHERE trd_no = ? LIMIT 1", [bid_no], function(err, rows) {
        console.log('rows==',rows);
});

In console I am getting:

rows== [ RowDataPacket { count: 0 } ]

Now I want to access the count value that is ‘0’, I have tried with array object but not getting. I need help in this.

How to send a webcam captured canvas image to the server side with php and plain Js

I am trying to create a simple program which captures an image on webcam, send it to the server to be saved in a database, and I would like to do that with plain Javascript and php.

So far I’ve managed to capture the image, but I am having hard time to get any contents into server side using AJAX.

<?php
if(isset($_POST['btn'])){
    // to see if there are any info saved.
    print_r($_FILES);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
    <body>
        <button id="start-camera">Start Camera</button>
        <video id="video" width="320" height="240" autoplay></video>
        
        <!-- post method to send the picture -->
        <form method="POST" action="" enctype="multipart/form-data">
            <button id="click-photo" name="btn" onclick="sendPic()">Click Photo</button>
            <canvas id="canvas" width="320" height="240" name="data"></canvas>
        </form>
    </body>
    <script>
        let camera_button = document.querySelector("#start-camera");
        let video = document.querySelector("#video");
        let click_button = document.querySelector("#click-photo");
        let canvas = document.querySelector("#canvas");
        const xhttp = new XMLHttpRequest();
        let file = null;
        
        // to open the camera
        camera_button.addEventListener('click', async function() {
            let stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false });
            video.srcObject = stream;
        });
        
        // to snap the picture
        click_button.addEventListener('click', function(){
            canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
        });

        // to send the picture
        function sendPic(){
            let blob = document.querySelector("#canvas").toBlob(function(blob) {
                    file = new File([blob], 'test.jpg', { type: 'image/jpeg' });
                    xhttp.open("POST", file);
                    xhttp.send();
                }, 'image/jpeg');
        }
    </script>
</html>

If there is any better implemantation while still using plain Js, please feel free to inform me about it

React Query: issue with index.js

I’m trying to connect React-query to my application by following the documentation. However, it shows me a bunch of errors: Image of an error

Index.js

import React from "react";
import ReactDOM from "react-dom/client";
import { QueryClient, QueryClientProvider } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
import "./index.css";
import App from "./App";
import { BrowserRouter } from "react-router-dom";

const root = ReactDOM.createRoot(document.getElementById("root"));

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false,
      retry: false,
    },
  },
});

root.render(
  <React.StrictMode>
    <BrowserRouter>
      <QueryClientProvider client={queryClient}>
        <ReactQueryDevtools initialIsOpen={false} />
        <App />
      </QueryClientProvider>
    </BrowserRouter>
  </React.StrictMode>
);

Generate an image from a chart visualforce page renderedAs pdf

Hello I have a problem with a visualforce page renderedAs pdf, I need to display chart with apexchart but it’s impossible to run javascript in a visualforce renderedAs pdf. My question is, is there any solution for doing that? I was thinking to calling another visualforce page (from the one renderedAs pdf) not rendered As pdf and run javascript there, then generate the data:image/png;base64 and returning this url from the second visualforce page (the one not renderedAs pdf) to apex controller. I don’t know if this can be done.
I hope someone can help me. THANKS!

How to build expo apk using eas build

After updating expo it no longer supports building apk files using expo build:android -t apk and instead advices to using eas builds using the command eas build -p android –profile preview but it ended up building an aab instead of the apk. I took a look at the newly added eas.json file which contained:

{
  "cli": {
    "version": ">= 0.52.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {}
  },
  "submit": {
    "production": {}
  }
}

I read the eas docs and it adviced on changing my eas.json to:

{
  "cli": {
    "version": ">= 0.52.0"
  },
  "build": {
    "preview": {
      "android": {
        "buildType": "apk"
      }
    },
    "preview2": {
      "android": {
        "gradleCommand": ":app:assembleRelease"
      }
    },
    "preview3": {
      "developmentClient": true
    },
    "production": {}
  }
} 

The after running the build command:eas build -p android –profile preview

It build the app correctly as an apk file and installs on android just fine, but on opening it closes itself instantly. After trying to reopen it again closes and now alerts the app crashed.

Is there an error in my eas.json file or am I miss something?

How to use a variable in a function that accepts “any”?

Hello I’ve faced the following issue, I’m trying to write a that will interact with a smart contract and the function accepts quite literally “any”, however I want it to be configurated within a setting so that it’s a variable.

            const mint = settings.MintFunction;
            const Transaction = await Contract.mint(1)

Result: it tries to interact with “mint”, instead of the mint function given in the settings (MintNFT)

The output I would like to have is

            const mint = settings.MintFunction;
            const Transaction = await Contract.MintNFT(1)

Current Error:

TypeError: Contract.mint is not a function

However I do not want to hardcode this but rather I want to be able adjust this in the json file.

Is there anyway to do this?