Skip to main content

Posts

Showing posts with the label Active questions tagged javascript - Stack Overflow

Form validation error message alert does not appear (JavaScript)

I have a form that, with JS, has an error message that is meant to appear when one or more of the fields in the form are left empty. However, when I click the submit button, nothing appears. HTML: <body> <script type=text/javascript src="script.js"></script> <h1>Organisation Score Calculator</h1> <!-- <h4>Input the name of the charity.</h4> <input type="text" id="nameOfOrganisation"> <h4>Which state/territory does this organisation service?</h4> <input type="text" id="state"> <h4>What is the ACNC listed size for this organisation?</h4> <input type="text" id="size"> <h4>What percentage of the organisation's total income is from government grants?</h4> <input type="text" id="governmentGrants"> <h4>How much net profit does the organisatio

How to show a loading spinner while fetching and compiling a component framework (Astro Island) Vue and AstroJS

I have the following astro page: --- import BaseLayout from '../../layouts/BaseLayout.astro'; import ListadoProfesionales from "../../components/pages/ListadoProfesionales/ListadoProfesionales.vue"; --- <BaseLayout title="Listado de profesionales"> <main class="container py-6"> <ListadoProfesionales client:only="vue" /> </main> </BaseLayout> The framework component "ListadoProfesionales" is rendering only in the browser with VueJS. How can I show a Spinner (or a loading UI element) while AstroJS is fetching and rendering that component? Via Active questions tagged javascript - Stack Overflow https://ift.tt/FTd7cAS

I'm having problems when sending User's Id's on a django model

I'm tryng to do a post method on projetos on my Vue Front-end but i keep getting the error message of "null value in column "professor_id" of relation "fabrica_projeto" violates not-null constraint" even though the request body is the same when i try to post on django-admin and it works there I'm kinda new to this whole coding world so sorry if my vocabulary is lacking On Vue/ my front-end enter image description here On Django-Admin(works) enter image description here enter image description here This is the model for Projeto enter image description here from django.db import models from usuario.models import Usuario from uploader.models import Image class Projeto(models.Model): nome = models.CharField(max_length=200) descricao = models.CharField(max_length=2500) data = models.DateTimeField(auto_now_add=True) professor = models.ForeignKey(Usuario, related_name='professor', on_delete=models.PROTECT) alunos = m

How to make Input Checkbox checked by default [closed]

<div \*ngFor="let serviceName of selectedServices_user" class="left-align-label"\> <label style="text-align: left;"\> <input class="left-align-label" type="checkbox" checked="true"\[(ngModel)\]="selectedServices_user\[serviceName\]" \[style.margin-top.px\]="i === 0 ? 10 : 0" style="text-align: left;"\> </label\> This is my html, please help me select all the checkboxes by default? Tried everything from checked to checked="true" doesn't seem to work Via Active questions tagged javascript - Stack Overflow https://ift.tt/OTmRClD

Open url directly after scan with html5-qrcode (javascript)

I used the html5qrscan code from geeksforgeeks ( url ) After successfully scanning the QR code a message including the url of the QR code is shown, I would prefer to automatically get redirected to the url. I have a project with a due date in a couple of days, but I no idea how to solve this. Help is very much appreciated! I've tried to fix it, but I'm clueless and I give up. Org. codes from geeksforgeeks: <!-- Index.html file --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> <title>QR Code Scanner / Reader </title> </head> <body> <div class="container"> <h1>Scan QR Codes</h1> <div class="section">

Unable to get id value in vanilla JavaScript [closed]

I am trying to fetch data from Pixabay api using JavaScript. Currently, I am able to display the api data but I am trying to create a separate page for each image id dynamically. For example, if someone click on one image, it should redirect to a different page called photos.html/id/photoname. JavaScript Code let editorChoice = document.querySelector('.editorchoice') async function getImg(){ let imgData = await fetch('https://pixabay.com/api/?key=12345&editors_choice') let imgRaw = await imgData.json() console.log(imgRaw) let itemData = imgRaw.hits //To create <div class="row"> in each row dynamically for(let i = 0; i < itemData.length; i++) { //Declare item variable and store itemData since itemData has stored api details let item = itemData[i] //i stands for those id starts from 0 in the api. //It won't possible to display image if we don't add i let imgId = item.id let imgType = item.type l

How to import a library only if it exists in Vite?

Let's say in my library I want to import an animation library only if the developer has installed it. Pseudo code as follows: let utility = null // If the library returns the library location as a string if (Boolean(require.resolve('animation-library'))) { import('animation-library').then(library => utility = library.helper) } Currently, on Vite (Rollup.js) you get a warning, as the import is analyzed on compilation. The above dynamic import cannot be analyzed by Vite. See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning. Via Active questions tagged javascript - Stack Overflow https://ift.tt/FfPtnER

How to increase timeout limit on Vercel Serverless functions

I have an API endpoint on a NextJS project that needs longer than 60s to run. I'm on a pro Vercel plan but for some reason cannot get the timeout limit to increase. At the endpoint itself I've tried export const maxDuration = 300 export const dynamic = 'force-dynamic' which doesn't seem to do anything, I also tried adding a vercel.json file at the top level (above /src ) like so: { "functions": { "pages/api/**": { "memory": 3008, "maxDuration": 300 }, } } Which again isn't working. I've combed through the documentation (mostly here ) and also a handful of threads ( one example ), none of which have helped. I'm running NextJs version 13.5.6 , am definitely on a pro plan, and Node v18, what am I doing wrong? Am really unsure of what else to try. Via Active questions tagged javascript - Stack Overflow https://ift.tt/Agu1h8b

Naming New Tab with Image

I am trying to rename a new tab I am opening up. This new tab contains an iframe with an image as the source. This is how I am opening the tab, but can't seem to get document.title to work. var customTab = window.open(); customTab && customTab.document.title = 'My new tab';//this doesn't work customTab && customTab.document.write( '<iframe src="' + myImage + '" style="border: none;"></iframe>' ); Any ideas would be much appreciated. Via Active questions tagged javascript - Stack Overflow https://ift.tt/Agu1h8b

Shopify Checkout Ui Extension Unable To Get address From ShippingAddress (API) Method Using Javascript

Need a function built that block checkout if it's an International Order with a PO Box. For international orders Shopify populates DHL Express as a shipping name. IF DHL Express and Address = PO Box in this condition we need to Block Progress of checkout. How to get the ShippingAddress using API in JavaScript code? First I need to get the address after that am going to validate if address have PO Box. Am not using react, am using the JavaScript. It seems there is no proper example for using the Ui Extension API with JavaScript. Here is my code. I am new to using the app with extension and I am not sure my code is correct. import { extension, } from "@shopify/ui-extensions/checkout"; // Set the entry point for the extension export default extension("purchase.checkout.delivery-address.render-before", renderApp); function renderApp(root, api, { extension, buyerJourney }) { const address = api.shippingAddress(); // Use the `buyerJourney` intercept to condi

How to solve this Error: read ECONNRESET or after second try then error occur is connection connect ECONNREFUSED 127.0.0.1:8000

The server is running fine and the registration API is also running fine and the registration is getting done. But when calling login API in postman this error is showing in console And error in server after call login API I want to call login API successfully. Via Active questions tagged javascript - Stack Overflow https://ift.tt/LXRVqZm

Gif not loading in react

I tried to fetch gif from giphy using API, bu[enter image description here][1]t the gif does not load useFetch.jsx import { useEffect, useState } from 'react'; const API_KEY = import.meta.env.VITE_GIPHY_API; const useFetch = ({ keyword }) => { const [gifUrl, setGifUrl] = useState(""); const fetchGifs = async () => { try { const response = await fetch(`https://api.giphy.com/v1/gifs/search?api_key=${API_KEY}&q=${keyword.split(" ").join("")}&limit=1`); const { data } = await response.json(); ; setGifUrl(data[0]?.images?.downsized_medium.url); } catch(error) { setGifUrl("https://metro.co.uk/wp-content/uploads/2015/05/pokemon_crying.gif?quality=90&strip=all&zoom=1&resize=500%2C284"); } }; useEffect(() => { if(keyword) fetchGifs(); }, [keyword]); return gifUrl; }; export default useFetch; How I've imported and implemented import useFetch from '../hooks/

Not allowed to use async/await while using serverActions in Client component in next.js

Building an infinite scroll in next.js, I am trying to call my serverAction to loadMoreData and using async/await with it to wait for the API call and get result. Getting an error: "async/await is not yet supported in Client Components, only Server Components." page.tsx is a server component and calls the same server action one time for initial images. // page.tsx const Home = async ({ searchParams }) => { const searchKeyword = typeof searchParams.keyword === "string" ? searchParams.keyword : ""; let apiResponse = await getPhotos({ query: searchKeyword }); return ( <main className='p-6 flex justify-center w-full min-h-screen bg-black'> <InfiniteScrollData search={searchKeyword} initialData={apiResponse?.results || []} /> </main> ); }; export default Home; Here is the server action: // actions.ts "use server"; export const getData = async ({ query, }) =&

I am having MongoDB Cast Error anyone know what this means?

I am having this unknown error but in my interface and Schema I am not defining any field with the property of ObjectId and this is probably the first ever error of it's kind to appear here so I really hope this gets fixed GET /auth/discord/redirect?code=MsYzdlnjVC6upRhp37LmK5HbFP9IPW 302 7085.898 ms - 64 /Discord Authentication/node_modules/mongoose/lib/schema/objectId.js:250 throw new CastError('ObjectId', value, this.path, error, this); ^ CastError: Cast to ObjectId failed for value "{ id: { discordId: '713145789463134269', globalName: 'URIZEN', _id: new ObjectId("65536ab9bec76a177731bb99"), __v: 0 } }" (type Object) at path "_id" for model "User" at SchemaObjectId.cast (/Discord Authentication/node_modules/mongoose/lib/schema/objectId.js:250:11) at SchemaObjectId.SchemaType.applySetters (/Discord Authentication/node_modules/mong

Can't import this github repo as a package: @openartmarket/pdfkit

Here's my code: https://github.com/ErnestoBorio/pdfkit-example I'm just trying to import the package https://github.com/openartmarket/pdfkit/ which is a fork of another package. The errors I get are: main.ts:1:25 - error TS2307: Cannot find module '@openartmarket/pdfkit' or its corresponding type declarations. Error [ERR_MODULE_NOT_FOUND]: Cannot find package './node_modules/@openartmarket/pdfkit/' imported from ./main.js Via Active questions tagged javascript - Stack Overflow https://ift.tt/ZwBOhfG

Stop execution of a recusive function that reads a JSON object with two nested object types

I have a JSON object built from two nested objects, both of which have a label property. My function checks that, for a given rank n, the array of QuestionModel[] or ResponseModel[] does not have equal labels. type ResponseModel = { label: string; questions?: QuestionModel[]; }; export type QuestionModel = { label: string; responses?: ResponseModel[]; }; const duplicatedLabel = async (data: QuestionModel[] | ResponseModel[]): Promise<boolean> => { const labelSet = new Set<string>(); for (let obj of data) { if (labelSet.has(obj.label)) { return true; } else { labelSet.add(obj.label); } if ("questions" in obj) return await duplicatedLabel(obj.questions!); if ("responses" in obj) return await duplicatedLabel(obj.responses!); } return false; }; For example, this JSON document is poorly constructed, with two equal labels at the same level yes . The funct

Push the dates to another list if dates in the first list are matching with the inserted dates

I have rooms list, and it's like this: const insertedDates = [2023-11-13, 2023-11-14, 2023-11-15]; const roomList = [ { name: "Room 1", price: 250, roomNumbers: [ { number: 104, unavailableDates: [2023-11-13, 2023-11-14, 2023-11-15] } { number: 102, unavailableDates: [] } ] } ] Firstly, I want to compare the inserted dates to rooms' unavailable dates. If the first room number's dates matches with them, pass to the next one. Then the room number's dates doesn't match with the inserted dates, it should be pushed in it. Expected: const roomList = [ { name: "Room 1", price: 250, roomNumbers: [ { number: 104, unavailableDates: [2023-11-13, 2023-11-14, 2023-11-15] } { number: 102, unavailableDates: [2023-11-13, 2023-11-14, 2023-11-15] } ] } ] Is it possible to do it in JavaScript? Via Active questions tagged javascript - Stack Overflow https://ift.tt/Ne1lc8

The TextInput clear and keyboard close every time i type(React Native)

Every time i type at Input in my app the text disappear and keyboard close, i searched forms to solve this but there is not many things, actually nothing that help me. Then this is my code, the useState: const [nameRoom, setNameRoom] = useState(''); The textInput: <TextInput style={styles.modalTextInput} onChangeText={(txt) => setNameRoom(txt)} value={nameRoom} /> I think that my code is ok, but i think that there is another thing on my full code that is cause of the problem Via Active questions tagged javascript - Stack Overflow https://ift.tt/Ne1lc8z

closeOnClick not working in materialize css dropdown

I have a website and i am using materialize css and i have a profile icon and when you click on that icon i show a dropdown having multiple sub-items but whenever i click on any sub-item, the dropdown disappears and i dont want. I tries these solution but not working Solutions that i have tried Solution - 1 $(".dropdown-trigger2").dropdown({ closeOnClick : false }); Solution - 2 $(document).ready(function(){ var elems = document.querySelectorAll('.dropdown-trigger2'); var instances = M.Dropdown.init(elems, {closeOnClick:false}); $(".dropdown-trigger2").dropdown('destroy'); $(".dropdown-trigger2").dropdown(); console.log(instances); }); Solution - 3 by using e.stopPropagation() But not of them is working/ here is my html code <a class="dropdown-trigger2 btn-user waves-effect waves-light guided-tour-notification-disabled drop-btn" href="#!" data-target="dropdown1">