Editing the order price in the Woocommerce dashboard to write the price on the order other than the original price, open the order image in large size on the order page
Category: javascript
Category Added in a WPeMatico Campaign
Cannot find module ‘preact’ or its corresponding type declarations [deno fresh]
im new to deno fresh and i was trying to set up a basic project but i cannot find a way to import the preact package into the project
when i try to do add this line import { h } from "preact"; it gives me the error
‘Cannot find module ‘preact’ or its corresponding type declarations’
sorry, but i cannot find the apposite tag for fresh.js since is a new framework and i don’t have enough points to create a new tag
the code that i’m trying to run is at the bottom of this page
https://fresh.deno.dev/docs/getting-started/create-a-route
How these variables be used without an error before initialization, can you help me understand [duplicate]
I want to understand why are variables were already declered even if I seem to declare them later?
const main = (function functio(params) {
console.log(2);
console.log(1);
function fun() {
button.addEventListener('click', () => {
console.log(input.value);
});
}
const input = document.querySelector('input');
const button = document.querySelector('button');
return (Object.freeze || Object)({
init: function (data) {
fun();
},
load: function (data) {},
});
})();
main.init();
Status tracking and props in hooks – How does React keeps (track) state and props in Hooks?
I know that in React class components React uses the “this” binding to “track” props and state. In hooks it is achieved thanks to closures, is my doubt?
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
This code works as you would expect a counter, if you were using class component you would have to use setState() in callback mode to access the previous state, but in hooks how does the magic happen?
are there any bindings on the hooks or not?
How to use if-else properly? [closed]
Converting this script to run as backend script instead of in HTML
I’m not very familiar with JS but I can poke around enough. I’m trying to use the following script as something that will run in the backend of my site instead of in HTML. As I understand it that is what “Angular” is for.
Essentially, I would like to do something along the lines of
var input = "ff0000";
var result = nearestColor(input)
console.log(result);
How would you set up this code to be backend only?
angular.module('myApp', [])
.controller('control', function($scope, $filter){
var colors = ["27b69d", "23a68f", "1aa48c", "17846f", "0f8b7d", "0e7e72", "0a876e", "097b64", "0a584d", "095046", "ffffff", "000000", "7e888e", "737c81", "383d40", "33373a", "272727", "018391", "017784", "db1e39", "c71b34", "fffee8", "ffb661", "fafafa", "e8e8e8", "d8d8d8", "e7f5f3", "5d6468", "4c5256", "31343b", "2f3335"];
$scope.colors = colors;
$scope.submit = function() {
$scope.new = $scope.newColor;
var res = [];
angular.forEach(colors, function(value, key) {
res.push(getDiffColor(value, $scope.newColor));
});
$scope.colors = $filter('filter')(colors, colors[res.indexOf(Math.min.apply(null, res))]);
};
$scope.raz = function () {
$scope.newColor = null;
$scope.colors = colors;
}
getDiffColor = function(cola, colb) {
a = hexToRgb(cola);
b = hexToRgb(colb);
return Math.sqrt(Math.pow((a.r - b.r),2) + Math.pow((a.g - b.g),2) + Math.pow((a.b - b.b),2));
}
function hexToRgb(hex) {
var result = /^#?([a-fd]{2})([a-fd]{2})([a-fd]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
});
Navigation bar can’t get on top of body
I want to make navbar rests on top of all components but when I open navigation menu it pushes all the components of index page down.
I am using Next js, Tailwind css and Framer motion.
It happens only when scroll top = 0 and when we scroll a bit it works as expected (comes on top of other components)
import { motion, AnimatePresence, useCycle, usePresent } from "framer-motion";
import { useState } from "react";
import Link from "next/link"
import React from "react"
import ThemeSwitch from "./ThemeSwitch"
import Burger from "./burger"
import { burg } from "./burger"
const sidebarVariants = {
open: {
opacity: "100%",
y: 0,
transition: {
duration: 0.5,
},
},
closed: {
opacity: "0%",
y: "-100vh",
transition: {
duration: 0.5,
delay: 1,
},
},
};
const Navigation = ( ) => {
const [isOpen, toggleOpen] = useCycle(false, true);
function navChange(){
toggleOpen()
}
function liToggle(){
toggleOpen()
burg()
}
return (
<>
<div
className="sticky top-0 z-20 py-2 bg-white/60 backdrop-blur md:py-6 md:mb-6 dark:bg-black/60 shadow-lg shadow-black/5 dark:shadow-white/5">
<div className="container px-4 mx-auto lg:max-w-4xl flex items-center justify-between transition duration-500">
<Link href="/">
<a
className={"font-medium tracking-wider transition-colors text-gray-900 hover:text-sky-500 dark:text-white hover:animate-pulse "}
>
Atharv Bilbile
</a>
</Link>
<div className="flex items-center justify-between">
<Link href="/"><a className="hidden md:flex px-3 py-2 rounded-3xl hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black" >Home</a></Link>
<Link href="/"><a className="hidden md:flex px-3 py-2 rounded-3xl hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black" >About</a></Link>
<Link href="/abnext"><a className="hidden md:flex px-3 py-2 rounded-3xl hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">Blogs</a></Link>
<Link href="/abnext">
<a className="hidden md:flex px-3 py-2 rounded-3xl hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">Contact</a></Link>
<ThemeSwitch />
<button onClick={navChange} className="md:hidden">
<Burger />
</button>
</div>
</div>
</div>
<AnimatePresence >
{ isOpen && (<motion.div variants={sidebarVariants}
initial={{ y: "-100vh"}} animate={isOpen ? "open" : "closed"} exit={{ opacity: "0%",
y: "-100vh" }} transition={{ duration: "1", delay: 0 }}
className="sticky top-12 z-10 flex justify-center py-9 bg-white/60 dark:bg-black/60 backdrop-blur shadow-2xl dark:shadow-white/5">
<ul className=" flex flex-col text-center">
<Link href="/"><a><li onClick={liToggle}
className="px-3 py-2 rounded-3xl hover:bg-black hover:text-white w-[200px] dark:hover:bg-white dark:hover:text-black hover:animate-pulse">Home</li></a></Link>
<Link href="/"><a><li onClick={liToggle} className="px-3 py-2 rounded-3xl hover:bg-black hover:text-white w-[200px] dark:hover:bg-white dark:hover:text-black hover:animate-pulse">About</li>.
</a></Link>
<Link href="/abnext"><a><li onClick={liToggle} className="px-3
py-2 rounded-3xl hover:bg- black hover:text-white w-[200px]
dark:hover:bg-white
dark:hover:text-black
hover:animate-
pulse">Blogs</li>.
</a></Link>
<Link href="/abnext"><a><li
onClick={liToggle}
className="px-3 py-2 rounded-
3xl hover:bg-black hover:text-
white w-[200px] dark:hover:bg-
white dark:hover:text-black
hover:animate-
pulse">Contact</li>.
</a></Link>
</ul>
</motion.div> )}
</AnimatePresence>
</>
)
}
export default Navigation;
I am making a comment system. My problem is when I post a comment and reload the page the comment is no more. What am I doing wrong?
I am making a comment system. My problem is when I post a comment and
reload the page the comment is no more. What am I doing wrong?
/ Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getDatabase();
// getting user input from form to store in firebase
const name = document.querySelector('.form--1');
const head = document.querySelector('.form--2');
const message = document.querySelector('.form--3');
// function for writing data to firebase for comments
> Here is where I get the data from the comment form for database
const postNewComment = function () {
set(ref(db, 'comments/'), {
Name: name.value,
Header: head.value,
Message: message.value
}).then(() => {
console.log('data stored successfully');
}).catch((error) => {
console.log('unsuccessful, error ' + error);
});
};
// code to post a comment -------------------------------------------------------------------------------->
> Everything else below is a function to create an html element and a function to receive data from database and post to dom but as I said it works but once I reload page the comment goes away.
const postBtn = document.querySelector('.btn--post');
// creates html elements
function elementFromHtml(html) {
const templat = document.createElement('template');
templat.innerHTML = html.trim();
return templat.content.firstElementChild;
}
const postComment = function (e) {
const sectionComments = document.querySelector('.scroll');
e.preventDefault();
postNewComment();
// reads data from firebase database and post comment to dom
const dbref = ref(db);
get(child(dbref, 'comments/')).then((snapshot) => {
if (snapshot.exists()) {
const commentData = snapshot.val();
console.log(commentData);
const html = `
<div class="row">
<div class="comments">
<figure class="comments__shape bg-color">
<img
src=""
alt=""
class="comments__image"
/>
<figcaption class="comments__caption">${commentData.Name}</figcaption>
</figure>
<div class="comments__text">
<h3 class="heading-tertiary u-margin-bottom-small f-title">
${commentData.Header}
</h3>
<p class="comments__story">
${commentData.Message}
</p>
</div>
</div>
</div>
`;
sectionComments.appendChild(elementFromHtml(html));
} else {
console.log('no data found');
}
}).catch((error) => {
console.log('unsuccessful, error ' + error);
});
// reset feilds
document.querySelector('.form').reset();
};
postBtn.addEventListener('click', postComment);
How can I set X-Frame-Options in javascript?
A while ago, I tried to embed a youtube video on my website. It gave me an error: that its X-frame-options was set to sameorigin and therefore could not load. After some research I learned that X-frame-options was an attribute which controlled whether a webpage could be embedded onto a different webpage. How can I set the X-frame-options header in my javascript code on my webpage? If this is not possible, please may you guide me to how I could control this on the server side?
The checkout. Isn’t working so the orders doesn’t show in the admin order page
My checkout isn’t working so the orders aren’t showing at the Canteen order
So I don’t know why the checkout isn’t working
I redirected to the success page and it’s giving me error
I need help
It is urgent for a project
Here is my github
https://github.com/abuhviktor/Finalyearproject/tree/main
I know the code isn’t dynamic but I am trying to be better everyday
I didn’t paste the code cause it’s alot
So any part u need I will paste it
How to access Django request body from Javascript?
I’m making the following request in JS to my Django API endpoint.
params = {"amount": String(amount), "currency": "usd", "description": "label"};
console.log(params)
var clientSecret = await fetch('https://url.com/api/payment/', {
method: 'POST',
body: params,
headers: {
'Content-Type': 'application/json'
},
}).then(r => r.json())
Here’s the view
def payment(request, *args, **kwargs):
print("here")
body = request.POST.copy()
print("present")
print(body)
print(type(body))
print(list(body))
headers_in = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer key',
}
response = requests.post('https://api.stripe.com/v1/payment_intents',
headers=headers_in,
data=params_in)
return Response(response.json()['client_secret'])
body = request.POST.copy() is giving me a Bad Request: /api/payment/
bad request in my logs
Add/Update Google Sheet Row Data Comparing Values from HTML Form Using Google Apps Script – Trying to Find Match on Sheet & Update Selected Row Data
I have an HTML form that allows users to populate the form from a Google Sheet, and successfully add new rows to the Sheet. I am trying to expand the function of my Apps Script to search the rows of entries for duplicates based on data from two columns and if there is a match, overwrite the existing row.
I know I need a for loop that iterates through each row in the Google Sheet to compare to the form data fields in question, but I don’t know how to access each.
This is a shortened example of the the form (the actual is much longer):
<form id="form">
<input name="firstName" />
<input name="lastName" />
<input name="someOtherField" />
<input name="someFourthField" />
<button onclick="SaveData">Save Data</button>
</form>
<script>
function SaveData() {
var formData = new FormData(document.getElementById("form"));
fetch('[APPS-SCRIPT-URL]',
{
method: 'post',
body: formData,
})
}
</script>
My Apps Script works perfectly when adding new rows, but either my for loop is not written correctly and thus not finding matches or otherwise setting the nextRow index isn’t working:
var sheetName = 'Entries'
var scriptProp = PropertiesService.getScriptProperties()
function setup () {
var doc = SpreadsheetApp.getActiveSpreadsheet()
scriptProp.setProperty('key', doc.getId())
}
function doPost (e) {
var lock = LockService.getScriptLock()
lock.waitLock(10000)
try {
var doc = SpreadsheetApp.openById(scriptProp.getProperty('key'))
var sheet = doc.getSheetByName(sheetName)
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]
var nextRow = sheet.getLastRow() + 1
var newRow = headers.map(function(header) {
return header === 'timestamp' ? new Date() : e.parameter[header]
})
var range = sheet.getRange(1, 1, sheet.getLastRow(), 2);
var rangeData = range.getValues();
// Here is where I am trying to loop and compare values
for(i = 1; i > rangeData.length; i++) {
// if the first two columns match the data entered on the form, change the "nextRow" variable to the index of the matching row
if(rangeData[i][0] == e.firstName && rangeData[i][1] == e.lastName) {
nextRow = i;
}
}
sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow])
return ContentService
.createTextOutput(JSON.stringify({ 'result': 'success', 'row': nextRow }))
.setMimeType(ContentService.MimeType.JSON)
}
catch (e) {
return ContentService
.createTextOutput(JSON.stringify({ 'result': 'error', 'error': e }))
.setMimeType(ContentService.MimeType.JSON)
}
finally {
lock.releaseLock()
}
}
With the above script, every form entry creates a new row, the match is never true. So I think there is something wrong either with my logic in matchfinding or the syntax I’m using to find the form values and spreadsheet data. So what am I missing?
Thanks!
My Checkout isn’t working and so the orders aren’t showing in the canteen order
My checkout isn’t working so the orders aren’t showing at the Canteen order
So I don’t know why the checkout isn’t working
I redirected to the success page and it’s giving me error
I need help
It is urgent for a project
Here is my github
https://github.com/abuhviktor/Finalyearproject/tree/main
I know the code isn’t dynamic but I am trying to be better everyday
I didn’t paste the code cause it’s alot
So any part u need I will paste it
Is there a way to access browser spell suggestions from javascript?
I am trying to make a search bar in my website which searches for a certain sentence in the database, I want to be able to correct the spelling of the form input before submitting it. I’ve noticed that there’s a red squiggly line when there’s a misspelled word in the input and when you right click it show’s suggestions. Is there any API to access these suggestions? I’ve tried different javascript libraries and none of them have accurate suggestions.
Is possible to change the Javascript code since the console?
When I make form I usually use JQuery Validator and I don’t validate the form in the server again. I would like to know if is possible that someone alter the HTML or Javascript from the code and remove my validations. If that is possible, what do you do in your developments to avoid this?
