dispatch Event does not execute

  document.getElementsByClassName('D(b) Pos(r) Expand')[5].click();


var message = document.getElementById('u1109464099');
var emojii = document.getElementById('emoji-picker-trigger');
emojii.click();

var grinsen = document.getElementsByClassName('emoji-picker__emoji')[1].click();


var keyEvent = new KeyboardEvent("keydown", { key: "Enter"});

var grinsen = document.getElementsByClassName('emoji-picker__emoji')[1].click();


document.getElementById('u1109464099').dispatchEvent(keyEvent);

If I execute the script, it won´t enter eventKey “Enter”.
It only returns “true” on the Chrome Console. Why? I thought dispatch event was to enter keys in browser?

index.ts:105 Uncaught TypeError: (0 , _firebase_util__WEBPACK_IMPORTED_MODULE_0__.getModularInstance)(…).onAuthStateChanged is not a function

when i am trying to go to my privet route show this error of firebase and my website crushed

this is error below :

    at onAuthStateChanged (index.ts:105:1)
    at index.esm.js:127:1
    at commitHookEffectListMount (react-dom.development.js:23049:1)
    at commitPassiveMountOnFiber (react-dom.development.js:24816:1)
    at commitPassiveMountEffects_complete (react-dom.development.js:24781:1)
    at commitPassiveMountEffects_begin (react-dom.development.js:24768:1)
    at commitPassiveMountEffects (react-dom.development.js:24756:1)
    at flushPassiveEffectsImpl (react-dom.development.js:26990:1)
    at flushPassiveEffects (react-dom.development.js:26935:1)
    at commitRootImpl (react-dom.development.js:26886:1)```

Property ‘error’ does not exist on type ‘{} | user | error’

  type user = {
    id: number,
    token: string
  }

  type errorObject = {
    error: string
  }

  interface authState {
      user: user | {} | errorObject,
  }

  const initialState: authState = {
      user: {}
  }

  const error : errorObject = {"error": "hi"}

  initialState.user = error

  console.log(initialState.user.error) // Property 'error' does not exist on type '{} | user | error'.

Why does this error? It has an error property so why does it say it doesn’t exist? I’m confused.

My goal was to make the user object to be any of these types:

user = {} 
// or
user = {"id": number, "token": "1234"}
// or
user = {"error": "error"}

JQuery animates activating not in right order

I develop a JQuery animation for my streams.
When a viewer buy a reward, an announcement appears on the screen.

The animation should display like this:

  1. A half opaque bar expands
  2. Titles slide in the center of the bar
  3. Titles slide out of the bar
  4. The bar shrinks to void

Nonetheless the fact that the delays look consistent to display the animation one after the other, the 3) and the 4) steps are playing at the same time.

const transition_duration = 1250;

let wait = 1000;
$('#announcement').delay(wait).animate({height: $('#announcement')[0].scrollHeight, padding: '10px 0 10px 0'}, transition_duration);

wait += 1000 + transition_duration;
$('#title-container').delay(wait).animate({left: `${($(window).width() - $('#title-container')[0].scrollWidth) / 2.}px`}, transition_duration);
$('#subtitle-container').delay(wait).animate({left: `${($(window).width() - $('#subtitle-container')[0].scrollWidth) / 2.}px`}, transition_duration);

wait += 4000 + transition_duration;
$('#title-container').delay(wait).animate({left: `-${$('#title-container')[0].scrollWidth}px`}, transition_duration);
$('#subtitle-container').delay(wait).animate({left: `100%`}, transition_duration);

wait += 1000 + transition_duration;
$('#announcement').delay(wait).animate({height: 0, padding: 0}, transition_duration);

Here is the full code: JSFiddle

You can display console to see the divergence of durations.

Thanks for your help

Cannot call prototype function from outside

I have a Mapper function that I want to call its prototype function method which is foo. However for some reason it’s not executing when I use mapper.prototype.foo(). Is there a way to call it outside of the function?

function Mapper() {
  return (site) =>
    new Promise((resolve, reject) => {
      resolve("yes");
    });
}

Mapper.prototype.foo = function() {
  console.log("afsd");
};

const mapper = new Mapper();
mapper.prototype.foo();
mapper("google.com");

How to find out if the user has enter any value in the input field in react

How to find out if the user has enter any value in the input field in react.

What I am trying to achieve is I would like to show a border around the card when the user enters the text/integer into one of the input fields inside that cards and does not click on the save button.

So border should be added to the card containing at least one of all the unsaved input fields and also changed input fields.

Card is a form repeater, wherein when I click on the “add a new row” button. the a new card will be added to the react page. this new card will have a same set of fields with the same default values. when the user changes any of the input field in the card. a border needs to be added to the card. if the user clicks on the save button the input fields should be saved.

When make changes to a individual input fields of a card, that card is indeed get a border, however when I add a new card. the border for the old card with unsaved input fields is removed.

I have been trying to solve this for a week now. I am not using formik or react-hook-form. I am using react-bootstrap library.

I am using a ternary statement to check if the fields are changed are not.

I am using a useState hook like this:

const [isFieldChanged, setisFieldChanged] = useState(false);
I am using handleClick function this to set useState variable:
    const handleClick = () => {
        setisFieldChanged(true);
    };

These are all the fields and this is how I have set the default value:

    const [inputFields, setInputFields] = useState([
        {
            fieldName: "",
            label: "",
            fieldSet: "",
            cardinality: 0,
            required: false,
            defaultValue: "",
            weight: 0,
        },
    ]);

Below is the code for ternary statement:

<Card
    id={`${inputField.id}`}
    className={
    isFieldChanged &&
    index !== 0 &&
    (inputFields.length) <= (index + 1) &&
    (inputField.cardinality !== 0 ||
    inputField.fieldName.length !== 0 ||
    inputField.label.length !== 0 ||
    inputField.fieldSet.length !== 0 ||
    inputField.required !== false ||
    inputField.defaultValue.length !== 0)
    ? " mt-2 border border-warning"
    : " mt-2 "
    }
>

For each of the form control I am adding onKeyPress to calling the handleClick function:

<Form.Control
    type="text"
placeholder="fieldName"
    name="fieldName"
    data-cy="name-text-field"
    value={inputField.fieldName}
    onChange={(event) => {
    handleInputChange(index, event);
    }}
    onKeyPress = {(event)=>{
    handleClick(index, event);
}
/>

Service Layer returns 401 unauthorized while calling GET API

When I call login API it returns :

“odata.metadata”: “https://00.00.00.00:50000/b1s/v1/$metadata#B1Sessions/@Element”,
“SessionId”: “ac0eeef4-cb70-11ec-8000-001e67fc647c”,
“Version”: “1000150”,
“SessionTimeout”: 150

After successfull login I try to call BusinessPartners API, it is a GET API.
When I call it in postman without any authentication it returns correct result, but when I call it in browser it returns 401 Unauthorized.

PUT does not update Mysql thru REST api / JWT

I am trying to make an update request using Jwt (Tokens) and Node.Js with a backend in mysql.
It just tells me in Postman that the record has been updated, i try to see where the update took place and i could not find a thing. Nothing updated.

My code is looking thus :

app.put('/api/v1/logistics/update_profile', async function (req, res, next) {

    try {

        if (!req.headers.authorization || !req.headers.authorization.startsWith('Bearer ') || !req.headers.authorization.split(' ')[1]) {
            return res.status(422).json({ message: 'Please Provide Token!' })
        }


        const theToken = req.headers.authorization.split(' ')[1];
        const decoded = jwt.verify(theToken, 'fasta-logistics');

        var fullname = req.body.fullname;
        var email = req.body.email;
        var state = req.body.state;
        var city = req.body.city;
        var phone_num = req.body.phone_num;
        var company_type = req.body.company_type;
        var company_name = req.body.company_name;
        var company_regnum = req.body.company_regnum;
        var l_licensenumber = req.body.l_licensenumber;
        var company_address = req.body.company_address;

        dbConn.query('UPDATE XXXXXx SET fullname =? , email =?, state=?, city=?, phone_num=?, company_type=?, company_name =?, company_regnum =?, l_licensenumber =?, company_address =?  where id =?', [fullname, email, state, city, phone_num, company_type,company_name,company_regnum, l_licensenumber, company_address, decoded.id], function (error, results, fields) {
            if (error) throw error;

            return res.send({ error: false, data: results, message: 'User Updated Successfully' });
        })


    } catch (err) {
        next(err);
    }
})

Why does it tell me the records has been updated and nothing happens? Please I need guidance here of some sort.

How to get the return value of stored procedure if it has more than 1 result

Hello (sorry im beginner), I have a stored procedure IN SQL that when it executes, it returns two select query, so basically 2 tables ( see image below)

enter image description here

In my controller, this is the example of how I get the value of the first table return

my controller:

 SqlDataReader dr = cmd.ExecuteReader();

               string column1= "";
               string column2= "";
               string column3= "";
               string column4= "";


               if (dr.Read())
               {
                  column1= dr["Column1"].ToString();
                  column2= dr["Column2"].ToString();
                  column3= dr["Column3"].ToString();
                  column4= dr["Column4"].ToString();

               }

               return Json(new { success = true, column1 = column1 , column2 = column2 , column3 = column3 , column4 = column4 }, JsonRequestBehavior.AllowGet);

How to get the result of the 2nd table? I tried like the approach above but it doesnt work and it doesnt return the first table result anymore. Thanks for help

Javascript – Dynamic Forms with Search Bar with Autocomplete Search

I have created a dynamic form in Javacript, which allows to add more fields. However, the fields is based on another Javascript function which creates a search bar with autocomplete search and recommendations .

The Search bar works with the first field – but when you add another field the recommendations do not show. How do I combine these two javascript functions to allow me to add more fields, and still search for the values?

Thanks.

Suggestions Box

Suggestions Box – Not Working with Another Field

sites.html

<div class="sites-container">
    <form class="sites-form" method = "POST" id="myForm" name="myForm">
         <div class="wrapper">
          <div id="Site-options">
            <h1 class="sites-add-header"> Create a Site </h1>
            <p class="sites-add-text"> Site name </p>
            <div class="search-input-site">
              <input type="text" placeholder="Choose Site Name" class="sites-add-input" name="Site Name"/>
            </div>
            <p class="sites-add-text"> Choose Modules at Site </p>
            <div class="wrapper2">
              <div class="search-input2">
                <a href="" target="_blank" hidden></a>
                <input type="text" placeholder="Type to search.." name="PV-modules">
                <div class="autocom-box2">
                </div>
                <div class="icon2"><i class="fas fa-search"></i></div>
              </div>
            </div>
            <p class="sites-add-text"> Modules Orientation </p>
            <div class="search-input-site">
              <input type="number" placeholder="If Empty Assumed Optimal" class="sites-add-input" name="Modules Orientation"/>
            </div>
            <p class="sites-add-text"> Modules Inclination </p>
            <div class="search-input-site">
              <input type="number" placeholder="If Empty Assumed 30 degrees" class="sites-add-input" name="Modules Inclination"/>
            </div>
          </div>
        <div class="controls">
          <a href="#" id="add_more_fields"><i class="fa fa-plus"></i>Add Another Site</a>
          <a href="#" id="remove_fields"><i class="fa fa-plus"></i>Remove Site</a>
        </div>
    </div>
    <button type="submit" class="sites-add-site button">Add Site</button>
  </form>
</div>

<script src="{{ url_for('static', filename='add-site.js') }}"></script>>

<script>
  let suggestions2 = {{ modules | safe}} ;
 </script>
<script src="{{ url_for('static', filename='auto-search-2.js') }}"></script>

add-site.js

var survey_options = document.getElementById('Site-options');
var add_more_fields = document.getElementById('add_more_fields');
var remove_fields = document.getElementById('remove_fields');

add_more_fields.onclick = function(){
  var _div = document.createElement('div');
  _div.setAttribute('id','new-div');
  _div.innerHTML =  '<h1 class="sites-add-header"> New Site </h1>' +
                    '<p class="sites-add-text"> Site name </p>' + 
                    '<div class="search-input-site">'+
                      '<input type="text" placeholder="Choose Site Name" class="sites-add-input" name="Site Name"/>' +
                    '</div>' +
                    '<p class="sites-add-text"> Choose Modules at Site </p>' + 
                    '<div class="wrapper2">' +
                      '<div class="search-input2">' +
                        '<a href="" target="_blank" hidden></a>' +
                        '<input type="text" placeholder="Type to search.." name="PV-modules">' +
                        '<div class="autocom-box2">' +
                        '</div>'+
                        '<div class="icon2"><i class="fas fa-search"></i></div>'+
                      '</div>'+
                    '</div>' +
                    '<p class="sites-add-text"> Modules Orientation </p>' +
                    '<div class="search-input-site">'+
                      '<input type="number" placeholder="If Empty Assumed Optimal" class="sites-add-input" name="Modules Orientation"/>'+
                    '</div>' + 
                    '<p class="sites-add-text"> Modules Inclination </p>'+
                    '<div class="search-input-site">'+
                      '<input type="number" placeholder="If Empty Assumed 30 degrees" class="sites-add-input" name="Modules Inclination"/>' + 
                    '</div>';

  survey_options.appendChild(_div);
};
remove_fields.onclick = function(){
  var elem = document.getElementById("new-div");
  elem.parentNode.removeChild(elem);
}

auto-search2.js

// getting all required elements
const searchWrapper2 = document.querySelector(".search-input2");
const inputBox2 = searchWrapper2.querySelector("input");
const suggBox2 = searchWrapper2.querySelector(".autocom-box2");
const icon2 = searchWrapper2.querySelector(".icon2");
let linkTag2 = searchWrapper2.querySelector("a");
let webLink2;
// if user press any key and release
inputBox2.onkeyup = (e2)=>{
    let userData2 = e2.target.value; //user enetered data
    let emptyArray2 = [];
    if(userData2){
        icon2.onclick = ()=>{
            webLink2 = `https://www.google.com/search?q=${userData2}`;
            linkTag2.setAttribute("href", webLink2);
            linkTag2.click();
        }
        emptyArray2 = suggestions2.filter((data2)=>{
            //filtering array value and user characters to lowercase and return only those words which are start with user enetered chars
            return data2.toLocaleLowerCase().startsWith(userData2.toLocaleLowerCase());
        });
        emptyArray2 = emptyArray2.map((data2)=>{
            // passing return data inside li tag
            return data2 = `<li>${data2}</li>`;
        });
        searchWrapper2.classList.add("active"); //show autocomplete box
        showSuggestions2(emptyArray2);
        let allList2 = suggBox2.querySelectorAll("li");
        for (let i = 0; i < allList2.length; i++) {
            //adding onclick attribute in all li tag
            allList2[i].setAttribute("onclick", "select2(this)");
        }
    }else{
        searchWrapper2.classList.remove("active"); //hide autocomplete box
    }
}
function select2(element){
    let selectData2 = element.textContent;
    inputBox2.value = selectData2;
    icon2.onclick = ()=>{
        webLink2 = `https://www.google.com/search?q=${selectData2}`;
        linkTag2.setAttribute("href", webLink2);
        linkTag2.click();
    }
    searchWrapper2.classList.remove("active");
}
function showSuggestions2(list){
    let listData2;
    if(!list.length){
        userValue2 = inputBox2.value;
        listData2 = `<li>${userValue2}</li>`;
    }else{
      listData2 = list.join('');
    }
    suggBox2.innerHTML = listData2;
}

Vercel: Cannot find module error while deploying a Monorepo

I have a lerna based monorepo with a Next.js app and several namespaced packages (@courselit) which are published on NPM and are used by the Next.js app.

When I am deploying the app on Vercel, I am getting the cannot find module error for all of my @courselit namespaced packages when they are published on NPM and I can install these packages by using `npm install @courselit/<package_name>’ command.

Any help is appreciated. I have lost two days as everything seems to work on local.

Here is the project: CourseLit

tag problem in html file in react js

Please cosnsider me as beginner. if you think this question is stupid, sorry for that

  1. I added html file in react js as “num.html”
  2. In that “num.html”, it has tag.
  3. I want to use that html file in my react component. so, i rendered in my app component.
  4. it was showing error like :

ERROR in ./src/num.html 1:0

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

  1. I want to use script tag on that html file . but react js not allowing. is there any alternative?