I started my journey to be a developer in January 2022. And I am still learning. Last 4 months, I learned HTML, CSS, javascript, two CSS frameworks (bootstrap, tailwind), and React (for js framework). Right Now, I am on the BackEnd Server side. For BackEnd I choose Node.js and Express.js (Node.js framework), Even for database, I learned MongoDB. All Of the tools are my beginning. I want to start my career as a react Developer. Ohhh. I forget to mention that I made 30+ short projects for learning. Now, I want to hear from the specialists, What I have to do for my goal.
Category: javascript
Category Added in a WPeMatico Campaign
ngIf with forEach javacript
This is sample code I’ve written
I’ve data in the specific order. I wish to add forEach to ngIf such that if the status of data is equal to yes then only it should print and also it should traverse through the whole array too.
Please help
Could you support me serving a client in Ecuador that requires help in modeling in Camunda and api rest?
I require advice on the modeling of Camunda, an expert on the subject urgently contact me by mail for a job that I have to do, I’m stuck on it. Thank you very much.
I hope soon one of the experts or co-founders can write me by mail to talk about a consultancy in Ecuador.Or recommend someone who speaks Spanish URGENT.
HTML Javascript buttons not responding while clicking
Whenever I click the increment button , it doesn’t show any output on the VS code terminal block.
It just shows the folllwing output “if ($?) { start firefox pEOPLEcOUNTERapp.htm }” just start the firefox browser and when i click on increment button then –> no output
HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<link rel = "stylesheet" href = "pEOPLEcOUNTERapp.css">
</head>
<body>
<h1> People Entered</h1>
<h2 id="count-el">0</h2>
<script src="pEOPLEcOUNTERapp.js">
// can write javascript
</script>
<button id="increment-btn" onclick="increment()">increment</button>
</body>
</html>
function increment(){ //javascript code
console.log("THE BUTTON WAS clicked")
}
JavaScript Code:
function increment()
console.log("THE BUTTON WAS clicked")
}
Running express server with vue/nuxt.js
My endpoints aren’t working, and most likely because the server on which express is isn’t running correctly. I run my files with npm run dev and my express files are in /middleware. The endpoint which I’m trying to fetch data from is in a route in /middleware/routes/crash.js. In my vue file I have axios preforming a get request to localhost:3000/api/crash/:id, however axios returns a 400 error indicating that the file hasn’t been found running on the server.
package.json:
"scripts": {
"dev": "nuxt",
/middleware/index.js:
const express = require('express')
const app = express()
const crash = require('./routes/crash')
app.use(crash)
module.exports = {
path: '/middleware',
handler: app
}
/middleware/routes/crash.js:
const { Router } = require('express')
const router = Router()
const crypto = require("crypto");
...
router.get('/api/crash/:id')
NodeJS: How to get a path a module was imported from
I have a module with some exported function that creates a file.
fs.appendFile(`${__dirname}/file_name`, 'aaaa', () => {});
When I import this module using a require syntax, when calling the function, the file is created in .node_modules/my_module/ (probably as expected). The question is how can I make it to create a file in the folder I’m calling this function.
I don’t have an option to inject the path when calling the function, in the real app it’s called by a third party reflection mechanism.
Why this const is undefined when it should be?
I have a form that gets the calculation of the insurance of a vehicle, I have reduced the code to only show the problem that I have (so if you see it incomplete it is because I reduced it).
My problem is that I have two input type radio, this for the user to choose one of two options and the problem comes when I try to pass the value of that constant from the “quoteInsurance” function to the prototype “UI.prototype.showResult”, when I read other constants like “year”, “brand”, this one gets the result, but when I do it with “selectedType” then it says the value is undefined.
//Variables
const form = document.querySelector("#cotizar-seguro");
//eventlisteners
eventlisteners();
function eventlisteners(){
form.addEventListener("submit", quoteInsurance);
}
//functions
//constructors
function Insurance(brand, year, type) {
this.brand = brand;
this.year = year;
this.type = type;
};
//Constructor object for the UI
function UI() {};
//prototype to show in the html the result of the calculation and the info of the Auto
UI.prototype.showResult = (insurance) => {
const {brand, year, selectedType} = insurance;
console.log(brand);
console.log(selectedType);
};
//instance ui
const ui = new UI();
function quoteInsurance(e) {
e.preventDefault();
//read selected brand
const brand = document.querySelector("#marca").value;
//read selected year
const year = document.querySelector("#year").value;
//read selected type
const selectedType = document.querySelector('input[name="tipo"]:checked').value;
//Initialize insurance
const insurance = new Insurance(brand, year, selectedType);
//we use the prototype to show result
ui.showResult(insurance);
};
body {
background: #e96443; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #904e95, #e96443); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #904e95, #e96443);
}
.btn.btn-raised.btn-primary {
background-color: #00838F!important;
font-size: 16px;
width: 100%;
padding: 15px;
}
.error {
background-color: #FBE9E7;
border: 1px solid #F4511E;
padding: 10px;
margin-bottom: 20px;
text-align: center;
color: #F4511E;
}
.correcto {
background-color: rgb(211, 249, 187);
border: 1px solid rgb(50, 167, 0);
padding: 10px;
margin-bottom: 20px;
text-align: center;
color: rgb(4, 150, 50);
}
.error p {
margin:0;
}
#contenido {
margin-top: 60px;
background-color: white;
-webkit-box-shadow: 0px 21px 46px -15px rgba(0,0,0,1);
-moz-box-shadow: 0px 21px 46px -15px rgba(0,0,0,1);
box-shadow: 0px 21px 46px -15px rgba(0,0,0,1);
}
.contenido-formulario {
margin-top: 30px;
}
#cargando {
text-align: center;
}
#cargando img {
display: none;
margin: 0 auto;
}
#resultado {
margin-bottom: 40px;
}
#resultado div {
border: 1px solid #26C6DA;
text-align: center;
padding: 0 0 20px 0;
}
#resultado div p {
margin-bottom: 0;
}
#resultado div p.header {
background-color: #26C6DA;
margin-bottom: 10px;
color:white;
padding: 10px;
text-transform: uppercase;
font-weight: bold;
}
.spinner {
margin: 50px auto;
width: 50px;
height: 40px;
text-align: center;
font-size: 10px;
}
.spinner > div {
background-color: #26C6DA;
height: 100%;
width: 6px;
display: inline-block;
-webkit-animation: sk-stretchdelay 1.2s infinite ease-in-out;
animation: sk-stretchdelay 1.2s infinite ease-in-out;
}
.spinner .rect2 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.spinner .rect3 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.spinner .rect4 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.spinner .rect5 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
@-webkit-keyframes sk-stretchdelay {
0%, 40%, 100% { -webkit-transform: scaleY(0.4) }
20% { -webkit-transform: scaleY(1.0) }
}
@keyframes sk-stretchdelay {
0%, 40%, 100% {
transform: scaleY(0.4);
-webkit-transform: scaleY(0.4);
} 20% {
transform: scaleY(1.0);
-webkit-transform: scaleY(1.0);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<div class="container mx-auto">
<div id="contenido" class="pb-10">
<header class="bg-teal-500 text-white py-3 font-bold uppercase">
<h1 class="text-center">Cotiza tu seguro de Auto</h1>
</header>
<form class="mt-10 max-w-lg mx-auto" action="#" id="cotizar-seguro">
<div class="flex items-center mb-5">
<label
class="font-bold uppercase mr-2 w-20"
for="marca"
>Marca:</label>
<select class="flex-1 bg-gray-100 p-3 appearance-none" id="marca">
<option value="">- Seleccionar -</option>
<option value="1">Americano</option>
<option value="2">Asiatico</option>
<option value="3">Europeo</option>
</select>
</div>
<div class="flex items-center mb-5">
<label
class="font-bold uppercase mr-2 w-20"
for="year"
>Año:</label>
<select class="flex-1 bg-gray-100 p-3 appearance-none" id="year">
<option value="2022">2022</option>
</select>
</div>
<fieldset>
<legend class="font-bold uppercase text-2xl text-center w-full">Tipo Seguro</legend>
<div class="flex justify-around mt-5">
<div>
<label class="font-bold uppercase mr-2">Básico</label>
<input type="radio" name="tipo" value="basico" checked>
</label>
</div>
<div>
<label class="font-bold uppercase mr-2">Completo</label>
<input type="radio" name="tipo" value="completo">
</label>
</div>
</div>
</fieldset>
<div id="cargando" class="hidden">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</div>
<div id="resultado"></div>
<div class="flex justify-center py-4">
<button
type="submit"
class="mx-auto bg-teal-500 hover:bg-teal-700 text-white font-bold py-2 px-20 rounded"
>Cotizar Seguro
</button>
</div>
</form>
</div> <!--#contenido-->
</div>
<script src="js/app.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</body>
</html>
Sticky Navigation bar tags
I’m very new to html/css/JS and I’ve made a sticky Navigation bar for my page but I’m having trouble with where the clickable area is for my tags on the navbar. I’ve some how gotten the clickable area to the left of my text not the text itself.
If someone could shed some light on what I’ve done wrong it would be a massive help.
Thanks!
<div class="page-navigation">
<nav id="navbar">
<div class="social">
<img src="Images/facebook-logo.png" alt="facebook link" />
<img src="Images/twitter-logo.png" alt="twitter link" />
<img src="Images/linkedin-logo.png" alt="linkedin" />
</div>
<img
src="Images/Logo-ADC%20Systems.png"
class="logo"
alt="Logo ADC Systems"
/>
<ul id="menu">
<li><a class="nav__links" href="index.html"></a>Home</li>
<li><a class="nav__links" href="About%20us.html"></a>About Us</li>
<li><a class="nav__links" href="Services.html"></a>Services</li>
<li><a class="nav__links" href="Contact%20us.html"></a>Contact Us</li>
</ul>
</nav>
.home-navigation{
width: 100vw;
height: 100vh;
background-image: url("Images/Home-Background.jpg");
background-size: cover;
}
.page-navigation{
width: 100vw;
height: 80vh;
background-color: #2D3142;
background-size: cover;
}
.social{
float: right;
padding-right: 0.8rem
}
.social img{
width: 40px
}
nav{
position: relative;
z-index: 1;
Width: 100%;
padding: 0px;
text-align: center;
box-sizing: border-box
}
#navbar a {
float: left;
color:#2D3142;
text-align: center;
padding: 14px;
text-decoration: none;
}
.logo{
width: 300px;
margin: 5px 0;
}
nav ul{
background: #FFFFFF;
width: 100%;
margin-top: 5px;
}
nav ul li{
position: relative;
display: inline-block;
list-style: none;
margin: 20px 30px;
color: #EF8354;
cursor: pointer;
}
#navbar ul li:hover{
color:#2D3142;
transition: 0.3s ease-out;
}
nav.sticky{
position: sticky;
top: 0;
left: 0;
padding: 10px 8%;
background: #FFFFFF;
display: flex;
align-items: center;
justify-content: space-between;
transition: padding 1s;
}
nav.sticky ul{
width: auto;
}
triplet extraction from unstructured text data
I’m new to programming and I want to extract triplets from unstructured text data
I already have regex matching the values that I want to extract.
I want the output file to look like this for each line :
name1|adress1|phone1
name2|adress2|phone2
name3|adress3|phone3
.
.
.
namen|adressn|phonen
thanks
Formatting complex JSON response to simple object
I’m trying to format complex response data returned by Strapi to obtain a simple object I can pass to my UI.
The GET request is to the following endpoint:
http://localhost:1337/api/projects?fields=title&populate=images
The output JSON response is as follows:
{
"data": [
{
"id": 4,
"attributes": {
"title": "Github Finder",
"slug": "github-finder",
"images": {
"data": [
{
"id": 29,
"attributes": {
"name": "Github-Finder.png",
"alternativeText": "Github-Finder.png",
"caption": "Github-Finder.png",
"width": 1349,
"height": 667,
"formats": {
"thumbnail": {
"name": "thumbnail_Github-Finder.png",
"hash": "thumbnail_Github_Finder_aa83f118aa",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 245,
"height": 121,
"size": 13.27,
"url": "/uploads/thumbnail_Github_Finder_aa83f118aa.png"
},
"large": {
"name": "large_Github-Finder.png",
"hash": "large_Github_Finder_aa83f118aa",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 1000,
"height": 494,
"size": 102.14,
"url": "/uploads/large_Github_Finder_aa83f118aa.png"
},
"medium": {
"name": "medium_Github-Finder.png",
"hash": "medium_Github_Finder_aa83f118aa",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 750,
"height": 371,
"size": 67.79,
"url": "/uploads/medium_Github_Finder_aa83f118aa.png"
},
"small": {
"name": "small_Github-Finder.png",
"hash": "small_Github_Finder_aa83f118aa",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 500,
"height": 247,
"size": 37.82,
"url": "/uploads/small_Github_Finder_aa83f118aa.png"
}
},
"hash": "Github_Finder_aa83f118aa",
"ext": ".png",
"mime": "image/png",
"size": 30.37,
"url": "/uploads/Github_Finder_aa83f118aa.png",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-05-03T05:33:46.174Z",
"updatedAt": "2022-05-03T05:33:46.174Z"
}
},
{
"id": 30,
"attributes": {
"name": "github-finder-desktop.png",
"alternativeText": "github-finder-desktop.png",
"caption": "github-finder-desktop.png",
"width": 1365,
"height": 777,
"formats": {
"thumbnail": {
"name": "thumbnail_github-finder-desktop.png",
"hash": "thumbnail_github_finder_desktop_8035dfa269",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 245,
"height": 140,
"size": 14.03,
"url": "/uploads/thumbnail_github_finder_desktop_8035dfa269.png"
},
"large": {
"name": "large_github-finder-desktop.png",
"hash": "large_github_finder_desktop_8035dfa269",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 1000,
"height": 569,
"size": 110.61,
"url": "/uploads/large_github_finder_desktop_8035dfa269.png"
},
"medium": {
"name": "medium_github-finder-desktop.png",
"hash": "medium_github_finder_desktop_8035dfa269",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 750,
"height": 427,
"size": 71.56,
"url": "/uploads/medium_github_finder_desktop_8035dfa269.png"
},
"small": {
"name": "small_github-finder-desktop.png",
"hash": "small_github_finder_desktop_8035dfa269",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 500,
"height": 285,
"size": 40.35,
"url": "/uploads/small_github_finder_desktop_8035dfa269.png"
}
},
"hash": "github_finder_desktop_8035dfa269",
"ext": ".png",
"mime": "image/png",
"size": 40.05,
"url": "/uploads/github_finder_desktop_8035dfa269.png",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-05-03T05:33:46.720Z",
"updatedAt": "2022-05-03T05:33:46.720Z"
}
},
{
"id": 31,
"attributes": {
"name": "github-finder-mobile.png",
"alternativeText": "github-finder-mobile.png",
"caption": "github-finder-mobile.png",
"width": 1079,
"height": 1919,
"formats": {
"thumbnail": {
"name": "thumbnail_github-finder-mobile.png",
"hash": "thumbnail_github_finder_mobile_1c2d812829",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 88,
"height": 156,
"size": 9.97,
"url": "/uploads/thumbnail_github_finder_mobile_1c2d812829.png"
},
"large": {
"name": "large_github-finder-mobile.png",
"hash": "large_github_finder_mobile_1c2d812829",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 562,
"height": 1000,
"size": 149.01,
"url": "/uploads/large_github_finder_mobile_1c2d812829.png"
},
"medium": {
"name": "medium_github-finder-mobile.png",
"hash": "medium_github_finder_mobile_1c2d812829",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 422,
"height": 750,
"size": 98.34,
"url": "/uploads/medium_github_finder_mobile_1c2d812829.png"
},
"small": {
"name": "small_github-finder-mobile.png",
"hash": "small_github_finder_mobile_1c2d812829",
"ext": ".png",
"mime": "image/png",
"path": null,
"width": 281,
"height": 500,
"size": 53.63,
"url": "/uploads/small_github_finder_mobile_1c2d812829.png"
}
},
"hash": "github_finder_mobile_1c2d812829",
"ext": ".png",
"mime": "image/png",
"size": 69.72,
"url": "/uploads/github_finder_mobile_1c2d812829.png",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-05-03T05:33:46.911Z",
"updatedAt": "2022-05-03T05:33:46.911Z"
}
}
]
}
}
}
],
"meta": {
"pagination": {
"page": 1,
"pageSize": 25,
"pageCount": 1,
"total": 1
}
}
}
My desired output is as follows :
{
title: "Github finder",
slug: "github-finder",
images: {
thumbnailUrl:"/uploads/thumbnail_Github_Finder_aa83f118aa.png",
largeImgUrl:"/uploads/large_Github_Finder_aa83f118aa.png",
mediumImgUrl:"/uploads/medium_Github_Finder_aa83f118aa.png"
smallImgUrl:"/uploads/small_Github_Finder_aa83f118aa.png"
},
}
Even the output in this format can be suitable
{
title: "Github finder",
slug: "github-finder",
images: {
image1:{
thumbnailUrl:"/uploads/thumbnail_Github_Finder_aa83f118aa.png",
largeImgUrl:"/uploads/large_Github_Finder_aa83f118aa.png",
mediumImgUrl:"/uploads/medium_Github_Finder_aa83f118aa.png"
smallImgUrl:"/uploads/small_Github_Finder_aa83f118aa.png"
},
image2:{
thumbnailUrl:"...",
largeImgUrl:"...",
mediumImgUrl:"..."
smallImgUrl:"..."
},
...
}
}
I’ve tried using various JS higher-order array functions but I have failed.
Draw lines on an image on web page using html and javascript
I opened the code from a web page and see this section:
<div id="box-5548" class="box box--size-size_xl" data-height="1140" data-width="1520">
<img alt='blocket' height='1140' src='gill.jpg' width='1520'><script type="text/plain" class="js-data">
{"lines":[[{"x":0.4,"y":0.4351},{"x":0.4605,"y":0.3158},{"x":0.4921,"y":0.214},{"x":0.5039,"y":0.2035}],
[{"x":0.4474,"y":0.6456},{"x":0.3,"y":0.3947},{"x":0.2961,"y":0.3737},{"x":0.2895,"y":0.3193},{"x":0.2842,"y":0.2965},{"x":0.2763,"y":0.2579}],
[{"x":0.4645,"y":0.6579},{"x":0.4737,"y":0.5439},{"x":0.4605,"y":0.4281},{"x":0.475,"y":0.314},{"x":0.4987,"y":0.2351},{"x":0.5105,"y":0.2105}],
[{"x":0.4895,"y":0.7474},{"x":0.4289,"y":0.6298}],
[{"x":0.5132,"y":0.7474},{"x":0.4816,"y":0.6702},{"x":0.475,"y":0.5982},{"x":0.4803,"y":0.5193},{"x":0.4724,"y":0.4333},{"x":0.4855,"y":0.3053},{"x":0.5079,"y":0.2439},{"x":0.5197,"y":0.2175}],
[{"x":0.6658,"y":0.3754},{"x":0.6684,"y":0.293},{"x":0.6724,"y":0.2404},{"x":0.6684,"y":0.2123}],
[{"x":0.8579,"y":0.5421},{"x":0.7526,"y":0.4509},{"x":0.6553,"y":0.4053},{"x":0.5197,"y":0.4193},{"x":0.4908,"y":0.414},{"x":0.4882,"y":0.3895},{"x":0.4908,"y":0.3491},{"x":0.5132,"y":0.2579},{"x":0.5289,"y":0.2281}]],
"options":{"style":"de_emphasized"},
"strong_line":[{"x":0.4895,"y":0.7474},{"x":0.4289,"y":0.6298}]}</script>
</div>
I am trying to figure out what is going on but I don’t quite understand.
I think this is the image: gill.jpg
Then, when looking at the page in a browser, lines are being drawn on the image (not altering the original gill.jpg).
Obvously the coordinates above are the seven lines drawn.
But the drawing itself is done by a script on the server? (js-data)?
Is there a well-know technique for doing this, is it possible to read about it somewhere?
Is there a way to detect keypress/enter in search event?
I am looking for a way to differentiate between pressing Enter in a input[type="search"] event (search-event), and clearing the query by pressing X.
I have tried looking for variables in e and e.target
The only thing I can think of is:
search.addEventListener("search", (e) => {
e.addEventListener("keypress", event => {
if (event.key === "Enter") {
....
}
});
});
But I don’t like this at all, and there is no way to specifically detect the pressing X.
Normally I use handler functions, so the code readability will suffer from this event nesting I think.
Is there a built in way or better way to achieve this? All help & thoughts are welcome!
Javascript Prototype best practice
im more like a script kiddy in js but now after some years after cheap coding i want to improve my js skills.
While reading around i found alot about the prototype concept of js but i can not manage it right i guess. Im just wondering how this things are managed today, because there was a lot of improvment in the last years. Let me make an example how i manage a classic js class/prototype:
I have a classic Login on my Webpage. I want the login system kind of dynamic, so i use some websocket and javascript to manage it. Therefor i build the Prototype LoginHandler:
function LoginHandler(websocket_subpath, email_id, username_id, password_first_id, password_second_id)
{
this.base_path = 'wss://' + window.location.host + websocket_subpath; // '/ws/main/login/'
var soc = new WebSocket(this.base_path);
soc.onmessage = this.read;
soc.onclose = function(e) {
console.log(e);
};
this.websocket = soc
this.email_id = email_id;
this.username_id = username_id;
this.password_first_id = password_first_id;
this.password_second_id = password_second_id;
this.email_final = "[email protected]";
}
LoginHandler.prototype.email_callback_final = function(){};
LoginHandler.prototype.read = function(e)
{
var data = JSON.parse(e.data);
var func = data['function'];
if(func == 'email_exists_final'){
var email = data['email'];
var email_exists = data['email_exists'];
if(email_exists == false){
LoginHandler.prototype.email_final = email;
console.log(e)
if(LoginHandler.prototype.email_callback_final != null)
{
console.log(e)
LoginHandler.prototype.email_callback_final();
}
}else{
console.log('Email ' + email + ' ist bereits vergeben.');
}
}else if(func == 'email_exists'){
var email = data['email'];
var email_exists = data['email_exists'];
if(email_exists == false){
console.log('Email ' + email + ' ist frei.');
}else{
console.log('Email ' + email + ' ist bereits vergeben.');
}
}else{
console.log("function not found.");
}
}
LoginHandler.prototype.email_exists = function()
{
var message = this.email_id.value;
var checker_text = check_email(message);
if(checker_text == ''){
var data = {
'function': 'email_exists_final',
'email': message
}
this.websocket.send(JSON.stringify(data));
}else{
document.getElementById("sign_notification").innerHTML = checker_text;
}
}
First of all, javascript has now this class abstraction stuff… why should i use this?
The other thing im realy woring about is the callback mechanism of the websocket.
I build the function prototype email_exists to dynamicly check if the username is already in the database. Then i create the read function as onmessage to process the answer. I decide to use json as transmission datatype, so i used some keys in the data to identify the functionality and functions i want to use. Here i just implement func == 'email_exists_final' situation.
In there i want to execute some function that was implementet by the user (email_callback_final), so just build a prototype of it and allow some implementation depending on the usecase of the Prototyp. e.g.:
LoginHandler.prototype.email_callback_final = function()
{
document.querySelector('.email-register-section').classList.add("fold-up");
document.querySelector('.password-register-section').classList.remove("folded");
}
It works fine but i can not believe that this is how u handle dynamik stuff like this in a good way.
So i just would like to get some tips and informations about better practice!
How to prevent function with parameters from being called on page load?
I have a function that is called after button is clicked. it looks like this
<button class=".." data-bind="click: $root.openModal">
Now I am trying to pass parameters to this function. Resulting in this code
<button class=".." data-bind="click: $root.openModal(Object.Keys(params))">
Parameters are passed successfully, but now whenever I load the page, before even clicking the button, openModal function is called. Same happens even if I leave ‘()‘ instead of openModal(Object.Keys(params)).
function itself, looks like this
self.openModal = function (keys) {
popupObservable(true);
self.modal = $.openModalDefault({
url: '#js-confirmation-dialog-template',
className: 'doc',
onLoad: function () {
popupObservable(false);
if (!$(selectors.confirmationModal)[0]) {
return;
}
var viewModel = new ConfirmationDialogViewModel(function () {
self.confirm(keys);
self.modal.close();
}, "This part is irrelevant");
ko.applyBindings(viewModel, $(selectors.confirmationModal)[0]);
}
});
};
What is the difference between openModal and openModal() and how do I pass parameters to this function without triggering it on page load?
How can i get the pinterest-like layout with tailwind and react?
i’m trying to get a pinterest-like layout but i cannot achieve it,
Here is the div of the card :
<div className='border-[1px] border-blanc rounded-[18px] w-[25rem] h-fit justify-between hover:bg-gray-400/5 cursor-pointer '>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
and here is the div that map all the card :
<div className='pt-[5rem] w-[90rem] ml-[2rem] grid grid-cols-3 '>
{datas.map((e) => (
<Card posterName={e.posterName} posterUsername={e.posterUsername} content={e.content} likes= {e.likes} dislikes={e.dislikes} commentsCount={e.commentsCount} key={e.id} id={e.id} repostCount={e.repostCount} image={e.image} />
))}
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
i tried flex-wrap, i tried grid but it doesn’t work, where is my error please ?