CKEditor support style attributes

 https://ckeditor.com/docs/ckeditor4/latest/guide/dev_allowed_content_rules.html

extraAllowedContent: '*[*]{*}(*)',

elements [attributes]{styles}(classes)
// A rule accepting <p> and <h1> elements, but without any property.
p h1

// A rule accepting <p> and <h1> elements with optional "left" and "right" classes.
// Note: Both elements may contain these classes, not only <h1>.
p h1(left,right)

// A rule accepting <p> and <h1> elements with all their attributes.
p h1[*]

// A rule accepting <p> and <h1> elements with all their attributes
// starting from 'data-'.
p h1[data-*]

// A rule accepting <a> only if it contains the "href" attribute.
a[!href]

// A rule accepting <img> with a required "src" attribute and an optional
// "alt" attribute plus optional "width" and "height" styles.
img[alt,!src]{width,height}

// The same as above, because the order of properties and their lists is irrelevant and white-spaces are ignored.
img { height, width } [ !src, alt ]
// Rules allowing:
// * <p> and <h1> elements with an optional "text-align" style,
// * <a> with a required "href" attribute,
// * <strong> and <em> elements,
// * <p> with an optional "tip" class (so <p> element may contain
//	a "text-align" style and a "tip" class at the same time).
p h1{text-align}; a[!href]; strong em; p(tip)

// Rules allowing:
// * <p> and <h1> elements with an optional "id" attribute,
// * <a> with a required "href" attribute and an optional "id" attribute.
p h1; a[!href]; *[id]

"AppendChild" same element multiple times in js

 https://dev.to/kiumad/can-you-appendchild-same-element-multiple-times-in-js-probably-not-4j

We can use cloneNode() , but I use another way
I want to use a function
like this :

//main function
function appendChildMultiple(parent) {
  //check function argument is an element
  if (parent.nodeType !== undefined) {
    const pTag = document.createElement("p");
    pTag.innerText = "This is the appended element";
    //finally append child to parent
    parent.appendChild(pTag);
  }
}

and use it :

const d1 = document.createElement("div");
const d2 = document.createElement("div");
appendChildMultiple(d1);
appendChildMultiple(d2);

How to validate start date and end date in bootstrap datepicker

 https://w3codegenerator.com/code-snippets/bootstrap/how-to-validate-start-date-and-end-date-in-bootstrap-datepicker

How to validate start date and end date in bootstrap datepicker

Through many examples, we will learn how to resolve the "How to validate start date and end date in bootstrap datepicker".

You can validate the start date and end date in the bootstrap datepicker. The end date must be after the date selected in the start date.
  • Start date and end date validation in bootstrap datepicker

    Bootstrap date picker CDN

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" integrity="sha512-mSYUmp1HYZDFaVKK//63EcZq4iFWFjxSL+Z3T/aCt4IO9Cejm03q3NKKYN6pFQzY0SBOr8h+eCIAZHPXcpZaNw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js" integrity="sha512-T/tUfKSV1bihCnd+MxKD0Hm1uBBroVYBOYSk1knyvQ9VyZJpc/ALb4P0r6ubwVPSGB2GvjeoMAJJImBG12TiaQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    

    HTML (Input date)

    <div class="form-group">
        <label for="startDate">Start Date *</label>
        <input type="text" class="form-control" name="start_date" id="startDate" value="" />
    </div>
    
    <div class="form-group">
        <label for="endDate">End Date *</label>
        <input type="text" class="form-control" name="end_date" id="endDate" value="">
    </div>
    

    javascript

    
    <script>
    //Start date and end date
    var start = new Date();
    // set end date to max one year period:
    var end = new Date(new Date().setYear(start.getFullYear()+1));
    
    $('#startDate, #endDate').datepicker('setDate', start );
    $('#startDate').datepicker({
        startDate : start,
        format: "yyyy-mm-dd",
        todayHighlight: true,
        autoclose: true,
        endDate   : end
    // update "toDate" defaults whenever "fromDate" changes
    }).on('changeDate', function(){
        // set the "toDate" start to not be later than "fromDate" ends:
        $('#endDate').val("").datepicker("update");
        $('#endDate').datepicker('setStartDate', new Date($(this).val()));
    }); 
    
    $('#endDate').datepicker({
        startDate : start,
        format: "yyyy-mm-dd",
        todayHighlight: true,
        endDate   : end
    }); 
    </script>
    
  • How can I set start and end dates for a Datepicker?

    var start_date = new Date().increment('week', 1);

    var end_date = new Date().increment('week', 5);

  • How to validate start date and end date in jQuery?

    You can do on two different dates for alert like this. $('#end_date').on('change', function(){ var startDate = $('#start_date').val(); var endDate = $('#end_date') }).

  • How can set current date in bootstrap Datepicker?

    Set current date in bootstrap datepicker.

    var date = new Date();
    var today = new Date(date. getFullYear(), date. getMonth(), date. getDate());
    var optSimple = {
    	format: 'mm-dd-yyyy',
    	todayHighlight: true,
    	orientation: 'bottom right',
    	autoclose: true,
    
  • How do I know if my Datepicker is loaded?

    You can check to see if the datepicker script has loaded using below script.

    if ($.fn.datepicker) { $('.datepicker').datepicker(); }

  • What is date parse in Javascript?

    The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31).

  • What is Autoclose in Datepicker?

    autoclose. Whether or not to close the datepicker immediately when a date is selected.

  • Does bootstrap have a time picker?

    Bootstrap time picker is a jQuery plugin which allows the user to select a time in the Bootstrap form without the necessity of using custom JavaScript code.

  • Is there a bootstrap Datepicker?

    Bootstrap date picker is a plugin that adds the function of selecting time without the necessity of using custom JavaScript code. This documentation may contain syntax introduced in the MDB 4.17.

  • How do I close Datetimepicker after selecting date?

    On change date function you can close the datepicker.

    $(document).ready(function () {
        $('#example1').datepicker({
            format: "dd/mm/yyyy",
            autoclose: true
        });
    
        //Alternativ way
        $('#example2').datepicker({
          format: "dd/mm/yyyy"
        }).on('change', function(){
            $('.datepicker').hide();
        });
    });

How To Get Last Record In Each Group In MySQL

 https://ubiq.co/database-blog/get-last-record-group-mysql/

Sometimes you may need to select most recent record or get latest record for each date,user, id or any other group. Here’s the SQL query to get last record in each group in MySQL, since there is no built-in function for it. You can also use it to select last row for each group in PostgreSQL, SQL Server & Oracle.

 

How To Get Last Record In Each Group In MySQL

Here are the steps to get last record in each group in MySQL.

Let’s say you have a table product_sales(product, order_date,sale) that contains sales data for multiple products.

mysql> create table product_sales(product varchar(255),order_date date, sale int);

mysql> insert into product_sales(product,order_date, sale)
     values('A','2020-05-01',250),
     ('B','2020-05-01',350),
     ('C','2020-05-01',1250),
     ('A','2020-05-02',450),
     ('B','2020-05-02',650),
     ('C','2020-05-02',1050),
     ('A','2020-05-03',150),
     ('B','2020-05-03',250),
     ('C','2020-05-03',1850);

mysql> select * from product_sales;
+---------+------------+------+
| product | order_date | sale |
+---------+------------+------+
| A       | 2020-05-01 |  250 |
| B       | 2020-05-01 |  350 |
| C       | 2020-05-01 | 1250 |
| A       | 2020-05-02 |  450 |
| B       | 2020-05-02 |  650 |
| C       | 2020-05-02 | 1050 |
| A       | 2020-05-03 |  150 |
| B       | 2020-05-03 |  250 |
| C       | 2020-05-03 | 1850 |
+---------+------------+------+

Bonus Read : How to Get Record with Max Value in MySQL

 

Let’s say you want to get last record in each group, that is, for each product. First we use GROUP BY to get most recent date for each group.

mysql> select product,max(order_date) from product_sales group by product;
+---------+-----------------+
| product | max(order_date) |
+---------+-----------------+
| A       | 2020-05-03      |
| B       | 2020-05-03      |
| C       | 2020-05-03      |
+---------+-----------------+

Now that we know the most recent date for each group, we join this result with our original table to get latest record by date group.

mysql> select product_sales.* from product_sales,
           (select product,max(order_date) as order_date
                from product_sales
                group by product) max_sales
             where product_sales.product=max_sales.product
             and product_sales.order_date=max_sales.order_date;
+---------+------------+------+
| product | order_date | sale |
+---------+------------+------+
| A       | 2020-05-03 |  150 |
| B       | 2020-05-03 |  250 |
| C       | 2020-05-03 | 1850 |
+---------+------------+------+

Bonus Read : How to Create View in MySQL

 

How to Select Most Recent Record for Each User

Similarly, you can select most recent record for each user or get latest record for each id. Let’s say you have the following table user_data(user_id,transaction_date,sale) with user transaction data

mysql> create table user_data(user_id int, transaction_date date, sale int);

mysql> insert into user_data(user_id,transaction_date, sale)
          values('1','2020-05-01',25),
          ('2','2020-05-01',35),
          ('3','2020-05-01',125),
          ('1','2020-05-02',40),
          ('2','2020-05-02',50),
          ('3','2020-05-02',50),
          ('1','2020-05-03',15),
          ('2','2020-05-03',25),
          ('3','2020-05-03',50);


mysql> select * from user_data;
+---------+------------------+------+
| user_id | transaction_date | sale |
+---------+------------------+------+
|       1 | 2020-05-01       |   25 |
|       2 | 2020-05-01       |   35 |
|       3 | 2020-05-01       |  125 |
|       1 | 2020-05-02       |   40 |
|       2 | 2020-05-02       |   50 |
|       3 | 2020-05-02       |   50 |
|       1 | 2020-05-03       |   15 |
|       2 | 2020-05-03       |   25 |
|       3 | 2020-05-03       |   50 |
+---------+------------------+------+

Bonus Read : How to Get New Users Per Day in MySQL

 

First, we get the latest date for each user id using GROUP BY.

mysql> select user_id,max(transaction_date) from user_data group by user_id;
+---------+-----------------------+
| user_id | max(transaction_date) |
+---------+-----------------------+
|       1 | 2020-05-03            |
|       2 | 2020-05-03            |
|       3 | 2020-05-03            |
+---------+-----------------------+

Now that we know the most recent date for each user id, we join this result with our original table to get the latest record by user group.

mysql> select user_data.* from user_data,
                (select user_id,max(transaction_date) as transaction_date
                     from user_data
                     group by user_id) max_user
                  where user_data.user_id=max_user.user_id
                  and user_data.transaction_date=max_user.transaction_date;
+---------+------------------+------+
| user_id | transaction_date | sale |
+---------+------------------+------+
|       1 | 2020-05-03       |   15 |
|       2 | 2020-05-03       |   25 |
|       3 | 2020-05-03       |   50 |
+---------+------------------+------+

Hopefully, you can get last record in each group in MySQL

StaticImage

  import React , { useEffect , useRef } from "react" import { StaticImage } from "gatsby-plugin-image" impor...