Form validation not working with ckeditor jquery

I am working with form validation, i have three fields (title,file,ckeditor),
validation is working only with “title and file” but whenever i try to validate “ckeditor” then
nothing is working for me,Here is my html code

<input type="text" class="form-control" name="title" id="title">
  <input class="form-control validate[required]" type="file" id="file" name="file">
  <textarea class="ckeditor" name="editor1" id="editor1"></textarea>
            

Here is my script code

<script>
 $().ready(function() {
 $("#addblog").validate({
          
            rules: {
                    title: {
                     required: true
                     },
                     file: {
                     required: true
                     },
                  'editor1': {
                    required:  required: function() 
                    {
                     CKEDITOR.instances.cktext.updateElement();
                    }
             },
             messages: {
                      file: {
                      required: "Please enter your image"
                  }
                 },
              ignore: [],   
        });
 });
</script>

Javascript wont executed in my html Django code

I have a very basic HTML code that i include in my Django project, however the Javascript wont load somehow in my project, the button seems do nothing, where i want to start my guidetour js.

The code is attached below

{% load static %}
<html>
  <head>
    <title>Tourguide Demo</title>
    <link rel="stylesheet" href="{% static 'css/base.css' %}">
    <link rel="stylesheet" href="{% static 'js/script.js' %}">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/LikaloLLC/[email protected]/tourguide.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/LikaloLLC/[email protected]/tourguide.min.js"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"/>
    <link rel="stylesheet" href="https://code.jquery.com/jquery-3.3.1.slim.min.js"/>
  </head>

  <body> 
  <h1 style="text-align:center;"> Tour Guide Demo.</h1>

  <div class="container">
    <div class="py-5 text-center">
      <h2>Checkout form</h2>
      <p class="lead">Below is an example usage of Tour Guide content based approach. Click [Start tour] button below to start the guided tour:</p>
      <p>
        <button class="btn btn-success btn-lg btn-block" id="tourbutton">
          Start tour
        </button>
      </p>
    </div>

    <div class="row">
      <div class="col-md-4 order-md-2 mb-4">
        <h4 class="d-flex justify-content-between align-items-center mb-3">
          <span class="text-muted">Your cart</span>
          <span class="badge badge-secondary badge-pill">3</span>
        </h4>
        <ul class="list-group mb-3" data-tour="step: 1; title: Your cart; content: Example cart description text displays cart description">
          <li class="list-group-item d-flex justify-content-between lh-condensed">
            <div>
              <h6 class="my-0">Product name</h6>
              <small class="text-muted">Brief description</small>
            </div>
            <span class="text-muted">$12</span>
          </li>
          <li class="list-group-item d-flex justify-content-between lh-condensed">
            <div>
              <h6 class="my-0">Second product</h6>
              <small class="text-muted">Brief description</small>
            </div>
            <span class="text-muted">$8</span>
          </li>
          <li class="list-group-item d-flex justify-content-between lh-condensed">
            <div>
              <h6 class="my-0">Third item</h6>
              <small class="text-muted">Brief description</small>
            </div>
            <span class="text-muted">$5</span>
          </li>
          <li class="list-group-item d-flex justify-content-between bg-light">
            <div class="text-success">
              <h6 class="my-0">Promo code</h6>
              <small>EXAMPLECODE</small>
            </div>
            <span class="text-success">-$5</span>
          </li>
          <li class="list-group-item d-flex justify-content-between">
            <span>Total (USD)</span>
            <strong>$20</strong>
          </li>
        </ul>

        <form class="card p-2" data-tour="step: 2; title: Promo code; content: Example cart promo code text displays promo code description">
          <div class="input-group">
            <input type="text" class="form-control" placeholder="Promo code">
            <div class="input-group-append">
              <button type="submit" class="btn btn-secondary">Redeem</button>
            </div>
          </div>
        </form>
      </div>
      <div class="col-md-8 order-md-1">
        <h4 class="mb-3">Billing address</h4>
        <form class="needs-validation" novalidate>
          <div class="row" data-tour="step: 3; title: Customer name; content: Example cart customer name text displays customer name description">
            <div class="col-md-6 mb-3">
              <label for="firstName">First name</label>
              <input type="text" class="form-control" id="firstName" placeholder="" value="" required>
              <div class="invalid-feedback">
                Valid first name is required.
              </div>
            </div>
            <div class="col-md-6 mb-3">
              <label for="lastName">Last name</label>
              <input type="text" class="form-control" id="lastName" placeholder="" value="" required>
              <div class="invalid-feedback">
                Valid last name is required.
              </div>
            </div>
            <div class="col-12">
              <p>
                <b>Example:</b> tour step describing the two fields abowe is added usigng the following html:
                <code>
                &lt;div class="row" data-tour="step: 3; title: Customer name; content: Example cart customer name text displays customer name description"&gt;
                </code>
              </p>
            </div>
          </div>

          <div class="mb-3">
            <label for="username">Username</label>
            <div class="input-group">
              <div class="input-group-prepend">
                <span class="input-group-text">@</span>
              </div>
              <input type="text" class="form-control" id="username" placeholder="Username" required>
              <div class="invalid-feedback" style="width: 100%;">
                Your username is required.
              </div>
            </div>
          </div>

          <div class="mb-3">
            <label for="email">Email <span class="text-muted">(Optional)</span></label>
            <input type="email" class="form-control" id="email" placeholder="[email protected]">
            <div class="invalid-feedback">
              Please enter a valid email address for shipping updates.
            </div>
          </div>

          <div class="mb-3">
            <label for="address">Address</label>
            <input type="text" class="form-control" id="address" placeholder="1234 Main St" required>
            <div class="invalid-feedback">
              Please enter your shipping address.
            </div>
          </div>

          <div class="mb-3">
            <label for="address2">Address 2 <span class="text-muted">(Optional)</span></label>
            <input type="text" class="form-control" id="address2" placeholder="Apartment or suite">
          </div>

          <div class="row">
            <div class="col-md-5 mb-3">
              <label for="country">Country</label>
              <select class="custom-select d-block w-100" id="country" required>
                <option value="">Choose...</option>
                <option>United States</option>
              </select>
              <div class="invalid-feedback">
                Please select a valid country.
              </div>
            </div>
            <div class="col-md-4 mb-3">
              <label for="state">State</label>
              <select class="custom-select d-block w-100" id="state" required>
                <option value="">Choose...</option>
                <option>California</option>
              </select>
              <div class="invalid-feedback">
                Please provide a valid state.
              </div>
            </div>
            <div class="col-md-3 mb-3">
              <label for="zip">Zip</label>
              <input type="text" class="form-control" id="zip" placeholder="" required>
              <div class="invalid-feedback">
                Zip code required.
              </div>
            </div>
          </div>
          <hr class="mb-4">
          <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="same-address">
            <label class="custom-control-label" for="same-address">Shipping address is the same as my billing address</label>
          </div>
          <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="save-info">
            <label class="custom-control-label" for="save-info">Save this information for next time</label>
          </div>
          <hr class="mb-4">

          <h4 class="mb-3">Payment</h4>

          <div class="d-block my-3" data-tour="step: 4; title: Payment; content: Example cart Payment text displays Payment description">
            <div class="custom-control custom-radio">
              <input id="credit" name="paymentMethod" type="radio" class="custom-control-input" checked required>
              <label class="custom-control-label" for="credit">Credit card</label>
            </div>
            <div class="custom-control custom-radio">
              <input id="debit" name="paymentMethod" type="radio" class="custom-control-input" required>
              <label class="custom-control-label" for="debit">Debit card</label>
            </div>
            <div class="custom-control custom-radio">
              <input id="paypal" name="paymentMethod" type="radio" class="custom-control-input" required>
              <label class="custom-control-label" for="paypal">PayPal</label>
            </div>
          </div>
          <div class="row">
            <div class="col-md-6 mb-3">
              <label for="cc-name">Name on card</label>
              <input type="text" class="form-control" id="cc-name" placeholder="" required>
              <small class="text-muted">Full name as displayed on card</small>
              <div class="invalid-feedback">
                Name on card is required
              </div>
            </div>
            <div class="col-md-6 mb-3">
              <label for="cc-number">Credit card number</label>
              <input type="text" class="form-control" id="cc-number" placeholder="" required>
              <div class="invalid-feedback">
                Credit card number is required
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-md-3 mb-3">
              <label for="cc-expiration">Expiration</label>
              <input type="text" class="form-control" id="cc-expiration" placeholder="" required>
              <div class="invalid-feedback">
                Expiration date required
              </div>
            </div>
            <div class="col-md-3 mb-3">
              <label for="cc-cvv">CVV</label>
              <input type="text" class="form-control" id="cc-cvv" placeholder="" required>
              <div class="invalid-feedback">
                Security code required
              </div>
            </div>
          </div>
          <hr class="mb-4">
          <button class="btn btn-primary btn-lg btn-block" type="submit" data-tour="step: 5; title: Continue; content: Example cart continue button text displays continue button description">Continue to checkout</button>
        </form>
      </div>
    </div>
  </div>
  </body>
</html>

The script.js is include in my {static} / folder which is already loaded.
///

  <script>
    var tourguide = new Tourguide();
    function startTour() {
      tourguide.start();
    }
    // Attach the touruide start evene to the button press
    var tourbutton = document.getElementById("tourbutton");
    tourbutton.addEventListener("click", startTour);
    </script>

However the interactive action seems failed to activate.

Below is the example output when successfully performed.
Example output

Getting nonexistent ‘Allow-Access-Allow-Origin’ header problem in nodejs application with express

I’m getting the “No ‘Access-Control-Allow-Origin’ problem” and tried some solutions that doesn’t worked for me.

Tried solutions:

app.use(cors({origin: '*', credentials: true}));
app.use((req, res, next) => {
    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', '*');

    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});

My code:

app.js

'use strict';

const express = require('express');
const bodyParser = require('body-parser');
const usersRoute = require('./routers/users-route');
const cors = require('cors');


const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

app.use('/store', usersRoute);

app.use(express.static('public'));

app.use(cors({origin: '*', credentials: true}));

module.exports = app;

server.js

'use strict';

const http = require('http');
const debug = require('debug')('nodejsservers:server');

const app = require('../src/app');

const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

const server = http.createServer(app);


server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

console.log('API rodando na porta: ' + port);

function normalizePort(val){
    const port = parseInt(val, 10);

    if(isNaN(port)) return val;
    if(port >= 0) return port;
    return false;
}

function onError(error){
    if(error.syscall !== 'listen') throw error;

    const bind = typeof port === 'string' ? 'Pipe ' + port :  'Port ' + port;

    switch(error.code){
        case 'EACCES':
            console.error(`${bind} requires elevated privileges`);
            process.exit(1);
            break;
        case 'EADDRINUSE':
            console.error(`${bind} is already in use`);
            process.exit(1);
            break;
        default: 
            throw error;
    }
}

function onListening(){
    const addr = server.address();
    const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
    debug('Listening on ' + bind);
}

How to pre-select the checkbox items coming from JSON data in React Component?

I need help in the react code. I am displaying the Checkboxlist of items using api. I need help in pre-select the Checkboxes on Page load. My JSON file contains the data having IsAssigned True/False. If isAssigned is true for that item, item checkbox will be pre-checked on page load.

Please find the react code. Please help me how this can be achieved. Please find my json data:

import React from "react";

export class SetDescItems extends React.Component { 

       constructor(props) {

             super(props);

             this.state = {

                    ProdDescrlist: [],

             }

       } 

       componentDidMount() {

                           this.getProdDescriptions();

       }   

async getProdDescriptions() {

             const url = "/api/getDescriptions”;

             await fetch(url)

                    .then(response => response.json())

                    .then((data) => {

                           this.setState({

                                 ProdDescrlist: data,

                                 loading: false

                           })

                    })

       }

       render() {

             return (

                    <div>

                           <form onSubmit={this.handleSubmit} >                          

<ul style={{ listStyle: 'none' }}>

               {

                      (this.state.ProdDescrlist.map((item, index) => {

                       return (

                       <li  key={index}>

                             <input type="checkbox" id={item.ProdDescription_ID}

                           value={item.DescriptionTextPlain} onChange={this.handleChange} />

                                      {item.DescriptionTextPlain}

                       </li>

                               )

                         }

                   ))

               }

          </ul>

  <button type="submit" >Submit</button>

</form>

  </div>

             );

       }

}

[{“ProdDescription_ID”:2863,”isAssigned”:”TRUE”,”DisplaySequence”:0,”DescriptionTextPlain”:”A1Testig”},

{“ProdDescription_ID”:2865,”isAssigned”:”TRUE”,”DisplaySequence”:0,”DescriptionTextPlain”:”test”},

{“ProdDescription_ID”:1778,”isAssigned”:”FALSE”,”DisplaySequence”:0,”DescriptionTextPlain”:”Testing4″},

{“ProdDescription_ID”:2864,”isAssigned”:”FALSE”,”DisplaySequence”:0,”DescriptionTextPlain”:”A2 “},

{“ProdDescription_ID”:1544,”isAssigned”:”FALSE”,”DisplaySequence”:5,”DescriptionTextPlain”:”ProductGuide”},

{“ProdDescription_ID”:1535,”isAssigned”:”TRUE”,”DisplaySequence”:10,”DescriptionTextPlain”:”testexample”},

{“ProdDescription_ID”:1536,”isAssigned”:”FALSE”,”DisplaySequence”:15,”DescriptionTextPlain”:”Note”}]

import React from “react”;

export class SetDescItems extends React.Component {

   constructor(props) {

         super(props);

         this.state = {

                ProdDescrlist: [],

         }

   } 

   componentDidMount() {

                       this.getProdDescriptions();

   }   

async getProdDescriptions() {

         const url = "/api/getDescriptions”;

         await fetch(url)

                .then(response => response.json())

                .then((data) => {

                       this.setState({

                             ProdDescrlist: data,

                             loading: false

                       })

                })

   }

   render() {

         return (

                <div>

                       <form onSubmit={this.handleSubmit} >                          
           {

                  (this.state.ProdDescrlist.map((item, index) => {

                   return (

                   <li  key={index}>

                         <input type="checkbox" id={item.ProdDescription_ID}

                       value={item.DescriptionTextPlain} onChange={this.handleChange} />

                                  {item.DescriptionTextPlain}

                   </li>

                           )

                     }

               ))

           }

      </ul>

Submit

         );

   }

}

ios image filter blur css has a boundary line

This boundary line is not permanent. It seems more like an ios rendering bug. Is there any workaround with css?

  • looks bad:

enter image description here

  • make some actions, like switching the app into background and reopen it, and the bug disappears
    enter image description here

the css of blurred background image is

.img {
    position: absolute;
    top: 0;
    left: 0;
    width: 80%;
    height: 100%;
    object-fit: cover;
    filter: blur(20px);
    opacity: 0.1;
}

How to remove Object keys from an array? [closed]

I’ve ended up with some messy code with an array inside an array, with a redunant object key, however I don’t know how to correct the format. Can anyone help me?

[
  [
    '621c0c5d1d0359d2cf92a16f',
    { votes: [Array], impactfulUser: '621c0c5d1d0359d2cf92a16f' }
  ],
  [
    '62a7d90d08e1756a5eac83c1',
    { votes: [Array], impactfulUser: '62a7d90d08e1756a5eac83c1' }
  ],
  [
    '607e33d3a5059e001920db69',
    { votes: [Array], impactfulUser: '607e33d3a5059e001920db69' }
  ]
]

Above is how I’ve ended up with the data, but how would I go about turning that into the below segment. Ie. I don’t want to have an array inside an array for no reason, and the object key is redundant. I’ve tried using Object.keys and Object.entries, but it keeps getting more and more nested.

[
      {
        votes: [Array], 
        impactfulUser: '621c0c5d1d0359d2cf92a16f'
      },
      {
        votes: [Array], 
        impactfulUser: '621c0c5d1d0359d2cf92a16f'
      },
      {
        votes: [Array], 
        impactfulUser: '621c0c5d1d0359d2cf92a16f'
      }
    ]

Any help would be great.

JavaScript – URL parameters not populating on next page

I have a radio button with specific values that I want to include in my URL parameters for the following pages (more than one). I have the parameters set up in the JS as var params.
in my, if-statement I have a console.log and location.href set to the next page desired based on the result.

  1. my issue is when I press the button it takes me to the page but not with the desired parameters.

  2. I also have 5 pages for each result following this page. how can I append the parameters to the following pages?

EPP1.HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Create Custom Evaluation Portal</title>
    </head>
    <body>
        <div id="bodyText"></div>
        <form id="myForm" action="EPV3.html" method="get">
            <div id="pBFContainer">
                <div id="bodyFOption1">
                    <label for="email">Enter email address:<p></label>
                    <input type='text' id='inputEmail' name='email' size="70"></input></div>
                <div id="bodyFTitle2"></div>
                <div id="bodyFOption2">
                    <label for="testType">Choose the test theme for your evaluation:<p></label>
                    <input id='rb1' class="optionT" type='radio' name='testType' value='voip' checked>VoIP<p> 
                    <input id='rb2' class="optionT" type='radio' name='testType' value='bandwidth'>Bandwidth<br><br>
                </div>
                <div id="bodyFTitle3"></div>
                <div id="bodyFOption3"></div>
            </div>
            <input type="submit" id="subButton" value="Next..." />
        </form>
    </body>
    <script type="text/javascript" src="EPP1.js"></script>
</html>

EPP1.js:

window.addEventListener("load", () => {
    let qs = decodeURIComponent(location.search.substring(1));
    let params = new Map();

    let parts = qs.split("&");
    parts.forEach((part) => {// i got this from a tutorial and liked it
        let key = part.split("=")[0];
        let val = part.split("=")[1];
        params.set(key, val);
    });

    if (params.get("testType") == "voip") {
        console.log("testtype is voip");
        window.location.href = "EvalPortalV3.html";
    } else if (params.get("testType") == "bandwidth") {
        console.log("testtype is bandwidth");
        window.location.href = "EvalPortalB3.html";
    }
});

Display results of an API request on HTML page using JavaScript

I have to build a page where the infos of countries (such as name, population, etc) are displayed using an API. I have managed to show the request results on the console using fetch, but I don’t know how to display the results in the HTML page. I’m a beginner and very unexperienced. I know very little js.

I’ve seen other topics like this one, but they didn’t really help solve my problem. One of them had an answer that suggested a code like the following, which worked fine until line 7 of the js script. However after adding the rest of the code I get an error that says Uncaught (in promise) TypeError: data is undefined. I don’t understand why it says data is undefined when it has been used before.

function displayAll() {
  let countriesList = [];
  let url = "https://restcountries.com/v3.1/all";

  fetch(url).then(function(response){
    response.json().then(function(data) {
      console.log(data);  // works fine up until here
    })
    .then((data) => { // error says that 'data' is undefined
      let countries = document.getElementById("countries-container");
      data.results.forEach((item) => {
        countriesList.push(item.name);
        let div = document.createElement("div");
        div.innerText = item.name;
        countries.appendChild(div);
      })
      console.log(countriesList)
    })
  });
}
<body onload="displayAll()">

  <header>Countries</header>
  
  <div class="container" id="countries-container">
  
    <!-- This is where the results will be displayed -->
  
  </div>

  <script src="./assets/scripts.js"></script>
  
</body>

I want to add new elements to serve as cards (one for each country).

Something tells me there will be more errors because the results printed in the console seem a bit too complicated to iterate, since it seems to be a matrix:

snipet of request result

snipet of request result expanded

I’m not using any frameworks, since I still need to learn more about the basics before jumping into the more fancy stuff. The code is just HTML, CSS and JavaScript and I want to keep it that way if possible. I’ve tried learning React alreaddy and I think I’m not ready yet… Anyway, if anybody can help me with this, I’ll be very grateful.

JS in USERSCRIPTS for tampermonkey

What i am trying to do is get my script to do is click the button on the webpage once the page loads and i had the script running but it was not actually clicking the button

this is the code

var $ = window.jQuery;

(document).ready(function() {
var crimePage = "https://camorra.world/crime/crime.php";
var gtaPage = "https://camorra.world/crime/gta.php";
var AmmoFactory = "https://camorra.world/business/ammo.php";
var KillPractice = "https://camorra.world/crime/killpractice.php";
var Times = "https://camorra.world/user/dashboard.php?times=";


 function bodyContains(string) {
    return $("body:contains('" + string + "')").length > 0;
}
if ($(location).attr('href') == gtaPage) {
    if (bodyContains("Grand Theft Auto")) {
        $(':button').each(function() {
            if (($(this).class() != "submit") && ($(this).class() != "submit") &&         ($(this).txt() != "Steal car from the street")) {
                this.click();
            }
        });
        $("input[button=Steal car from the street]").click();
        return;
    }
}

});

I am very new to this so when answering could you be very detailed so that i know how to fix this correctly if you need more info just let me know and i will post what ever you need.

Thank you,
Macs

A Javascript visualization library for drawing market or industry landscape maps [closed]

I would like to draw a market landscape map like the one below that shows categories(industry) and icons of the companies within the categories. (The number of companies within each category is dynamic)

However, I cannot find a library to draw this kind of diagram. Is there any JS library available for this? Thank you in advance for your help!

Market Landscape Map