input field doesnt allow to edit

Hi guys I am trying to edit the input field below and cant.
I getting some data from a server and I am putting this data on the value of the input. The idea is that one we click the icon to allow the field to be editable but still cant edit.

This is the input with props customised:


 <input
          {...field}
          //   required={props.required}
          disabled={props.disabled}
          value={props.value}
          type={props.type}
          autoComplete={props.autoComplete}
          pattern={props.pattern}
          className={`mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm  rounded-md ${
            error ? 'border-red-500' : 'border-gray-500'
          }
          ${
            props.disabled
              ? 'disabled:shadow-none disabled:bg-slate-50 disabled:text-slate-500 disabled:border-slate-200'
              : 'border-gray-500'
          } `}
        />

And here is where I am actually using it. So once I click the icon its value comes true but cant edit inside the already value that returns from the server.


const [agent, setAgent] = useState<EstateAgentResponse | null>(null)
  const [enableField, setEnableField] = useState<boolean>(false)

  useEffect(() => {
    const fetchData = async () => {
      try {
        const { id } = params

        const agentUsers = await getEstaAgentUsers(parseInt(id!, 10))
        const agent = await getEstateAgentById(parseInt(id!, 10))

        setAgentUsers(agentUsers)
        setAgent(agent)
      } catch (error) {
        // ToDo:
        // We should handle the error message
        toast.error(`${error}`)
      }
    }
    fetchData()
  }, [])

 const handleInputField = () => {
    setEnableField(!enableField)
  }

<PencilAltIcon className="block h-4 w-4" aria-hidden="true" onClick={handleInputField} />
                              <InputField
                                name="businessName"
                                label="Business name"
                                disabled={!enableField}
                                value={agent?.businessName}
                                type="text"
                                rules={{
                                  required: 'This is required',
                                }}
                              />

how to find specefique html element by keyword?

im having problems on how to find a specifique html element when having a keyword:

…

<div class="col-sm-6 col-md-6 col-lg-4">
    <div class="ct-itemProducts ct-u-marginBottom20" >
                                    <div class="ct-main-content">
                                    
                                        <div class="ct-main-text" >
                                            
                                            <div class="ct-product--tilte">
                                                COMPUTIME
                                            </div>
                                            ...
                                        

my keyword is COMPUTIME aand i whant to detect className of this div

<div class="col-sm-6 col-md-6 col-lg-4">

Service worker in NX/React workspace can”t be register because of “import”

I have a workspace in react where I am trying to setup service workers.

in main.tsx I do :

import * as serviceWorkerRegistration from './serviceWorkerRegistration';

serviceWorkerRegistration.register({
  onSuccess: () => pwaStore.setState((state) => ({ ...state, isReady: true })),
  onUpdate: () => pwaStore.setState((state) => ({ ...state, hasUpdate: true })),
});

serviceWorker.js is the same as the default one from pwa-template, I just changed this line to work with NX.

      const swUrl = `${process.env.NX_PUBLIC_URL}/service-worker.js`;
      registerValidSW(swUrl, config);

service-worker.js is the default one and contains some imports

import { clientsClaim } from 'workbox-core';
import { ExpirationPlugin } from 'workbox-expiration';
import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate } from 'workbox-strategies';

Now, when I deploy and run this project, I am prompted with

Error during service worker registration: DOMException: Failed to register a ServiceWorker for scope (‘xxx’) with script (‘xxx/service-worker.js’): The script has an unsupported MIME type (‘text/html’).

So, I guess the service-worker is not found when loading from direct url. So I added it on the build

        "assets": [
          "apps/core/src/service-worker.js",
          "apps/core/src/manifest.json",
          "apps/core/src/robots.txt",
          "apps/core/src/favicon.ico",
          "apps/core/src/assets"
        ],

and now, it does find it, but I get prompted with

Uncaught SyntaxError: Cannot use import statement outside a module (at service-worker.js:1:1)

I am unsure on how to fix this now.

React html parser not working with nexjts

I am fetching data from api,There is description field (data saved by ckeditor)

In my db/api data is saving in following format

&lt;p&gt;&lt;strong&gt;Hello admin &lt;em&gt;Lorem Ipsum dummy text&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

And i am using “ReactHtmlParser” for display blog content in web page

{ReactHtmlParser(post.description)}

But its showing me data in following format,how can i solve this ?

<p><strong>Hello admin <em>Lorem Ipsum dummy text</em></strong></p>

My expected output is ”
Hello admin Lorem Ipsum dummy text “

Click Button in Parent, get data from Child to Parent and use it in a method (Vue 3)

I’m working with Vue3 and Bootstrap 5.

MY PROBLEM: I want to click a button in my parent.vue. And after clicking this I want to have the data from my child.vue inside of the method in my parent.vue - method .

But my data is always empty, except I need another “`setTimeout”-function. But actually I don’t want to use it.

I think there is a better solution for the props Boolean as well..

If there are any question left regarding my problem, please ask me!

Thanks for trying helping me out!

PARENT:

<template>
  <Child :triggerFunc="triggerFunc" @childData="childData"/>
  <button type="button" class="btn btn-success" @click="get_data()">Get Data</button>
</template>

<script>
  export default {
    data() {
      return {
        triggerFunc: false,
        c_data: [],
      }
    },
    
    methods: {
    
      childData(data) {
        this.c_data = data;
      },
    
      get_data() {
        this.triggerFunc = true;
        setTimeout(() => {
          this.triggerFunc = false;
        }, 50);
        
        console.log(this.c_data);
        //HERE I WANT TO USE "C_DATA" BUT OF COURSE IT's EMPTY. WITH ANOTHER SET_TIMEOUT IT WOULD WORK 
        //BUT I DON'T WANT TO USE IT. BUT WITHOUT IT'S EMPTY. 


        //LIKE THIS IT WOULD WORK BUT I DON'T WANT IT LIKE THAT
        setTimeout(() => {
          console.log(this.c_data);
        }, 50);
      }
    },
  }
</script>

CHILD:

<template>
  <!-- SOME BUTTONS, INPUTS, ETC. IN HERE -->
</template>

<script>
  export default {
    data() {
      return {
        input1: "",
        input2: "",
      }
    },
    
    props: {
      triggerFunc: Boolean, 
    },
    
    triggerFunc(triggerFunc) {
       if(triggerFunc == true) {
         this.save_data()
       }
     }
    
    methods: {
      save_data() {
      var data = [
        {
          Input1: this.input1,
          Input2: this.input2
        },
      ]

      this.$emit("childData", data);
    },
    },
  }
</script>

How I can solve this error in setValues function “The parameters (number[]) don’t match the method signature for SpreadsheetApp.Range.setValues” [duplicate]

I’m pre-filling a Google form with AppScript, finally I’m saving the urls in an array.

var formCol = SpreadsheetApp.getActive().getRangeByName('FORM');
var form = FormApp.openByUrl(FORM_URL);
var items = form.getItems();

var urls = [];
for (let i = 1; i < 4; i++ ) {
    
    var formResponse = form.createResponse();

    var formItem = items[0].asTextItem();
    response = formItem.createResponse(botData.id[i]);
    formResponse.withItemResponse(response);

    formItem = items[1].asTextItem();
    response = formItem.createResponse(botData.bot[i]);
    formResponse.withItemResponse(response);

    var date = new Date (botData.date[i].toString());
    var date2 = botData.date[i].toString();
    
    //var day
    formItem = items[3].asTextItem();
    response = formItem.createResponse(botData.zone[i]);
    formResponse.withItemResponse(response);

    formItem = items[8].asTextItem();
    response = formItem.createResponse(botData.remitent[i]);
    formResponse.withItemResponse(response);

    formItem = items[9].asTextItem();
    response = formItem.createResponse(botData.description[i]);
    formResponse.withItemResponse(response);

    formItem = items[11].asTextItem();
    response = formItem.createResponse(botData.solutiontime[i]);
    formResponse.withItemResponse(response);


    var url = formResponse.toPrefilledUrl();
    //sheet.getRange(row, 31).setValue(url);
    url = url.toString()
    urls.push(url)
    
  }
  formCol.setValues(urls);
}

I want to print each url in a ‘FORM’ column of Google Sheets but I get the error “
Exception: The parameters (number[]) don’t match the method signature for SpreadsheetApp.Range.setValues.” when I try to print the array with setValues, how I can solve this error?

How to convert camel casing into normal text [duplicate]

I have a props debtType which can be either “loan” or “overdraft” or “creditCard” And I want to convert this props and display it as “Loan”, “Overdraft”, “Credit Card”. I currently use this function –

const capitalize = (str: string) => {
        return str.charAt(0).toUpperCase() + str.slice(1);
    };

But problem with this is that it displays “creditCard” props as “CreditCard” and I want it as “Credit Card”. Can someone please help me with this?

Wheel Size – math formulas

I would like to implement the tire size configurator. Starting from the width of the wheel alone, how can I find the values, in percentages, of the height / width ratio? I also ask for the same thing to obtain compatible diameters.

How do I export Media Queries in React?

I want to store Media Queries in a separate file to be able to reuse in other files.

import { useMediaQuery } from 'react-responsive'
const MediaQueries = () => {
    const isDesktopOrLaptop = useMediaQuery({
        query: '(min-width: 810px)'
    })
    const isLargerThanMobile = useMediaQuery({ query: '(min-width: 480px)' })
    const isBigScreen = useMediaQuery({ query: '(min-width: 1824px)' })
    const isTabletOrMobile = useMediaQuery({ query: '(max-width: 480px)' })
    const isPortrait = useMediaQuery({ query: '(orientation: portrait)' })
    const isRetina = useMediaQuery({ query: '(min-resolution: 2dppx)' })
}


export default MediaQueries

I’ve tried importing the values below to other files and using the various media queries, and it doesn’t work.

import MediaQueries from '../media-query/MediaQueries'
...
MediaQueries.isLargerThanMobile

Finding pattern in data and structuring it

I’ve a sheet where I paste data from the website, when I paste, it look like this in sheet(Page 1 and Page 2):-
enter image description here

I am trying to make it structured, something like this in javasrcipt :-
enter image description here

Don’t know how to start, column has multiple property data which I want to structure

Here is the sheet link:- https://docs.google.com/spreadsheets/d/1M9YUR2NEc0IUvpwmzw1diMSMG9ukZw-269Rvg531WqY/edit#gid=0

Any suggestions?

Unable to type into input field

I’m trying to store user input in local storage and had it functioning. But because I will need to test it, I have changed my code and made a function that will work as a custom hook, that I will call in my tests also.
Now the page is rendering but I am not able to type into the input box?
When hovered over the box the mouse cursor doesn’t even respond as if it isn’t an input field.

I believe the problem lies in my useStateWithLocalStorage function:

import { useState, useEffect } from 'react';

const useStateWithLocalStorage = (defaultValue, key) => {
  const [value, setValue] = useState(() => {
    const storedValues = localStorage.getItem(key);

    return storedValues !== '' ? JSON.parse(storedValues) : defaultValue;
  });

  useEffect(() => {
    localStorage.setItem(key, JSON.stringify(value));
  }, [key, value]);

  return [value, setValue];
};

export default useStateWithLocalStorage;

In particular this line

return storedValues !== '' ? JSON.parse(storedValues) : defaultValue;

The value before anything is parsed into the localstorage should be name: ”

Here is my component:

import React from 'react';
import { Container, Title } from '@mantine/core';
import useStateWithLocalStorage from './Handlers';

const UserForm = () => {
  const [inputValue, setInputValue] = useStateWithLocalStorage('', 'form');

  function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
    event.preventDefault();
  }

  function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {
    setInputValue((previousValues) => ({
      ...previousValues,
      [event.target.name]: event.target.value,
    }));
  }
  return (
    <Container>
      <Title order={2}>Welcome {inputValue.name}</Title>
      <form onSubmit={handleSubmit}>
        <label htmlFor="name">
          Name
          <input
            type="text"
            name="name"
            id="name"
            placeholder="enter your name"
            onChange={handleChange}
            value={inputValue.name}
          />
        </label>
      </form>
    </Container>
  );
};

export default UserForm;

I hope I’ve explained myself well enough and haven’t wasted anyone’s time. I’d be thankful for any help.

Next.JS disable moving outside source code into pages

I have a custom next.js server and a regular typescript program. I would like the next.js APIs to communicate with the regular program, but when I do that, the code from my regular program gets moved into any page that accesses it.

One of the API routes:

import { getTokens } from '../../../src/managers/tokens';

export default function handler(req: NextApiRequest, res: NextApiResponse) {
    res.status(200).send({'success': true, 'tokens': getTokens()});
}

A section of the built API route:

module.exports = import("ws");;

/***/ }),

/***/ 147:
/***/ ((module) => {

module.exports = require("fs");

/***/ }),

/***/ 919:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ handler)
/* harmony export */ });
/* harmony import */ var _src_managers_tokens__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(480);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_src_managers_tokens__WEBPACK_IMPORTED_MODULE_0__]);
_src_managers_tokens__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];

Those requires are never used in the API file, the entire tokens.ts file gets moved and duplicated into the built API route. This separates all of the variables in the module scope.

My aim is to have the built next.js routes separate to the regular typescript program.