JavaScript – Comments duplicating on another div

I am creating a comment box and I managed to append whatever I type to a div I wanted, however I have added another input and trying to append that along with the comments, however when I do this the second time, the previous duplicates. I know I’m doing something wrong in my display_commnents function, however I’m not entirely sure what it could be, basically I just want whatever is entered on both title and comments to append on the comment-box with title on top and comment just below. Below is my code:

<div class="container">
    <h1>Write New Post</h1>
    <form>
        <input id="title" type="text" placeholder="Title" value="">
        <textarea id="" placeholder="Leave us a comment" value=""></textarea>
        <input id="giphy" type="text">
        <div class="btn">
            <input id="submit" type="submit" value="comment">
            <button id="clear">Cancel</button>
        </div>
    </form>
</div>
<div class="comments">
    <h2>Comments</h2>
    <div id="comment-box" value="submit">
    </div>
</div>

And this is my JS code:

    const title = document.querySelector('#title')
const field = document.querySelector('textarea');
const textBackUp = title.getAttribute('placeholder')
const backUp = field.getAttribute('placeholder')
const btn = document.querySelector('.btn');
const clear = document.getElementById('clear')
const submit = document.querySelector('#submit')
// const comments = document.querySelector('#comment-box')
const titleText = document.getElementById('title')
const comments = document.getElementById('comment-box')

let title_arr = [];
let comments_arr = [];

title.onfocus = function(){
    this.setAttribute('placeholder', '')
}

title.onblur = function(){
    this.setAttribute('placeholder', textBackUp)
}

field.onfocus = function(){
    this.setAttribute('placeholder','')
    this.style.borderColor = '#333'
    btn.style.display = 'block'
} // when clicking on this, placeholder changes into ' ', border colour changes and buttons will appear.

field.onblur = function(){
    this.setAttribute('placeholder',backUp)
} //click away, placeholder returns

const display_comments = () => {
    let list = '<ul>'
    title_arr.forEach(title => {
    comments_arr.forEach(comment => {
        list += `<li>${title} <br>${comment}`
    })
    })
    list += '</ul>'
    comments.innerHTML = list
}

clear.onclick = function(e){
    e.preventDefault();
    btn.style.display = 'none'
    title.value = ''
    field.value = ''
    display_comments()
}

submit.onclick = function(e){
    e.preventDefault();
    const head = title.value;
    const content = field.value;
    if(head.length > 0){
        title_arr.push(head)
        display_comments();
        title.value = '';
    }
    if(content.length > 0){
        comments_arr.push(content)
        display_comments();
        field.value = '';
    }
}

any help would be appreciated

ExtJS Chart Legend itemclick listener doesn’t work

I have a trouble with triggering ExtJS legend event.

For instance, in this fiddle I want to fire itemclick:

https://fiddle.sencha.com/#view/editor&fiddle/3j0c

But nothing happens.

Ext.create({
   xtype: 'polar',
   renderTo: document.body,
   width: 400,
   height: 400,
   theme: 'green',
   legend: {
    docked: 'bottom',
     listeners: {
        itemclick: function() {
            console.log("Item clicked");
        }
    },
    },
   interactions: ['rotate', 'itemhighlight'],
   store: {
       fields: ['name', 'data1'],
       data: [{
           name: 'metric one',
           data1: 14
       }, {
           name: 'metric two',
           data1: 16
       }, {
           name: 'metric three',
           data1: 14
       }, {
           name: 'metric four',
           data1: 6
       }, {
           name: 'metric five',
           data1: 36
       }]
   },

   series: {
       type: 'pie',
       highlight: true,
       angleField: 'data1',
       label: {
           field: 'name',
           display: 'rotate'
       },
       donut: 30
   }
});

How do I allow copy-pasting of HTML tables into an HTML textarea tag?

TinyMCE, CKEditor, and Froala allow you to copy-paste HTML tables (e.g. from an email or Wikipedia) directly into the HTML textarea and the HTML table structure and tags are preserved.

For an additional example, my web-based email client can also do this. I can copy an HTML table from an email I received into an email I am sending, and the table structure will be preserved.

I understand that these editors are not just HTML textareas, rather they are rich text editors. My question: What browser capabilities allow for rich text editing? How do they do this?

From what I can tell, every time I copy-paste some HTML into a textarea, the browser strips out all HTML tags.

How to add image into axios data

I would like to add an image into Axios data and send the data to .Net Controller. I have never done this before with an image and I need help.
The image source it’s not coming from input, but from img tag.

Any idea how to insert the image into a JSON object(data)?
Thank you in advance!

 function PostOffer(){
            let localhost = "https://localhost:7009";
            let url = localhost + "/Client/New";
            let formClientName = document.getElementById("offer-client-name").value;
            let formClientEmail = document.getElementById("offer-client-email").value;
            let formClientPhone = document.getElementById("offer-client-phone").value;
            let formClientDate = document.getElementById("offer-client-date").value;
            let formClientTotal = document.getElementById("main-calculator-total-amount-final").innerText;

            if(parseFloat(formClientTotal) > 0){
                if(formClientName.trim() != "" && formClientEmail.trim() != "" && formClientPhone.trim() != "" && formClientDate.trim() != ""){
                let data = {
                clientName : formClientName,
                clientEmail : formClientEmail,
                clientOfferDate : formClientDate,
                clientPhone : formClientPhone,
                clientTotal : formClientTotal,
                };
                axios.post(url, data)
                    .then(function (response) {
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    })
                ClearOfferSend();
                }else{
                    document.getElementById("validation-inputs-send-offer").style.display = "flex";
                }
            }else{
                 document.getElementById("validation-inputs-send-offer").style.display = "flex";
                 document.getElementById("validation-inputs-send-offer").innerText = "Total amount can not be 0";                 
            }
            
        }
            <div class="final-form">
                <input type="text" asp-for="Name" id="offer-client-name" placeholder="name" required/>
                <input type="email" asp-for="Email" id="offer-client-email" placeholder="email" required/>
                <input type="text" asp-for="Phone" id="offer-client-phone" placeholder="phone" required/>
                <label for="DateOffer">When do you want to start the project?</label>
                <input type="date" asp-for="DateOffer" id="offer-client-date" placeholder="date" required/>
                <div class="row">
                        <button class="btn-close-final-offer" onclick="CloseOfferForm();">Close</button>
                        <button class="btn-send-final-offer" onclick="PostOffer();">Send</button>
                </div>
                <span id="validation-inputs-send-offer">Inputs can not be empty!</span>
            </div>

Failing Vercel deploy with error TypeError: Cannot read property ‘split’ of undefined at multiple objects

I’m trying to deploy my webapp for the first time and I’m getting this error on Vercel:

TypeError: Cannot read property ‘split’ of undefined
at Object.3qS3 (/vercel/path0/.next/serverless/pages/[collection]/[templateId].js:2510:16)

I’m recieving the error regarding multiple objects. I believe this is what’s causing the issue:

  const balanceAmount = parseFloat(
    currentUserBalance.split(' ')[0].replace(/[,]/g, '')
  );

I don’t understand what’s causing the issue.

In updateMany, update the field only if field exists, and do not create a new key

So what I want to do inside the $set is check if the field exists and then update the value, but only if this field exists. The $cond is very close to what I want to achieve but the problem is I can’t stop it from creating the field.

I could filter to get only the existing field, but in this case I would have to update field by field instead of all at the same time, and this would take forever.

 const data = await connection.collection("snapshot").updateMany({}, [
    {
      $set: {
        field1: {
          $cond: [
            { field1: { $exists: true } },
            { field1: "newValue" },
            undefined, // do nothing
          ],
        },
        field2: {
          $cond: [
            { field2: { $exists: true } },
            { field2: "newValue" },
            undefined, // do nothing
          ],
        },
        field3: {
          $cond: [
            { field3: { $exists: true } },
            { field3: "newValue" },
            undefined, // do nothing
          ],
        },
      },
    },
  ]);

Am I missing something or is just impossible to do?

I’m using mongo 5.0

ngModel path to bind from variable

I have a configuration object that specifies a path to model like this

configuration class object{ path: string }
path = myObject.id
I want to use this path on template as as a property of [(ngModel)]. I can’t use it with {{}}, is there any way to use string variable as a path to binding?

Decode stream Payload in kheiron Studio

I want to decode a smart sensor and integrate it into kheiron studi, for that i need to write a javascript function.enter image description here

Or my sensor decoder in ttn ( the things network) is on this github link: https://github.com/SensationalSystems/smart_building_sensors_decoder/commit/e977f3ba7b0b7f8a9eb0db80394b6bbddcd564b3

can anyone help me o adapt this code to work with in kheiron studio

Thank you.

MVC core 5.0 update js via Viewmodel

im trying to update data in javascript via viewmodel.
When the side loads it works.

     window.addEventListener('load', function () {
        let listModel = @Html.Raw(Json.Serialize(Model));
        LoadAllInfoSpots(listModel);
    
    });

But when i call my js function

function afterClickOnFlorplan() {
        setTimeout(function () {
           let listModel [email protected](Json.Serialize(Model));
        LoadAllInfoSpots(listModel);
        }, 1500);

    }

the let listmodel is the same as when i loaded the side. with a count of 4.

i know the viewmodel is updating.
pic of the viewmodel updatede

but as you can see let listmodel is not updated in my js code.

old listmodel

So why is the let listmodel the same all the time?

hope you can help me.

Model:

 public class SelectorModel
    {
        public int? ID { get; set; }
        public string ImageName { get; set; }
        public string Cords { get; set; }
        public string Name { get; set; }
    }

ViewModel:

 public class SelectorViewModel
    {
        public List<SelectorModel> SelectorModels { get; set; }

    }

the first IActionResult:

public IActionResult Index()
        {
            LoadInfoSpotsFromDB load = new LoadInfoSpotsFromDB();
            string first = load.LoadFirstImage();
            SetFirstIMageCookie(first);
            List<SelectorModel> loaede = load.Load(first);
            selectorViewModel = new SelectorViewModel
            {
                SelectorModels = loaede
            };           

            return View(selectorViewModel);
        }

the IActionResult that update the ViewModel

[HttpPost]
        public IActionResult Index([FromBody] string dontremove)
        {
            selectorViewModel = null;
            LoadInfoSpotsFromDB load = new LoadInfoSpotsFromDB();            

            List<SelectorModel> loaede = load.Load(HttpContext.Request.Cookies["ImageName"]);            

            selectorViewModel = new SelectorViewModel
            {
                SelectorModels = loaede
            };


            return View(selectorViewModel);
        }

jquery-modal keeps last input

I want to use the jquery-modal plugin to make comments for several form elements. Its working fine, as long there is no keyboard input. Otherwise it remembers the last input and keeps that in the textarea, even if I empty it before.

This is the form that is shown in the modal window.

<a title="" href="#" onclick="getRechKomm('12345'); return false;" class="edit_komm">Kommentar</a>

<form id="RechKommForm" class="none">
    <h3></h3>
    <p><textarea name="kommentar" id="ptrRechKomm"></textarea></p>
    <p><input type="hidden" name="rechid" id="ptrRechKommID" value=""></p>
</form>

<script>
    function getRechKomm(rechnr){
        $('#ptrRechKomm').html('');
        $.ajax({
            type: "POST",
            url: "ptr_getrechkomm.php",
            data: {rechnr: rechnr},
            success: function(data){
                readSession();
                $('#ptrRechKomm').html(data);
                $('#ptrRechKommID').val(rechnr);
                $('#RechKommForm').modal({
                    escapeClose:false,
                    clickClose: false,
                    fadeDuration:500
                });
            }
        });
    }
    $('#RechKommForm').on($.modal.BEFORE_CLOSE, function(event, modal) {
        $.ajax({
            type: 'POST',
            url: 'ptr_putrechkomm.php',
            cache: false,
            data: $("#RechKommForm").serialize(),
            success: function (data) {
                $('#ptrRechKomm').html('');
                $('#ptrRechKommID').val();
            }
        });
    });
</script>

So if call the comment for the ID 12345 and write a comment “Komm 12345”, everything is fine. After that I call the comment for ID 23456, that may be already “Komm 23456”. It is loaded from the database and put into the textarea #ptrRechKomm, but the first text is still there. So in the textarea is “Komm 12345Komm 23456”.

Where is the old content coming from and how to delete it?

DataTables and export to excel – number formating

$(document).ready(function () {
    $.fn.dataTable.moment(lang == "en" ? 'DD/MM/YYYY' : 'DD.MM.YYYY');
    categories_table = $('.datatable').DataTable({
        order: [[1, 'desc']],
        language: datatable_lang,
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'collection',
                autoClose: 'true',
                text: '<i class="download icon">',
                tag: 'span',
                buttons: ['csv', 'print', 'excel']
            }
        ]
    });
});

This gives nice looking format for price, like “8,00” as example. But when I export that to excel, I get “800” as value. And if number is “18,00”, excel will show it as “1,800”.

Is there any way to sort this out and have same values in excel as well?

Thanks

Modernizr is not defined. A very simple browser check but not working?

Modernizer is not working.
my console here

Trying to check for browsersupport with css grids.

My script in the HTML file:

<!-- Browser support check using Modernizer -->
  <script  src="../src/modernizr.js"></script>
  <script>

    if (Modernizr.cssgrid, cssgridcssgridlegacy) {
      alert('ok!')
    } else {
      alert('no ok!')
    }

  </script>

  <!-- End browser support check -->

I have modernizr-config.json and modernizr.js files in my src folder. index.html in my public folder. Overall a React app.
Basically I followed this guide here: https://www.youtube.com/watch?v=wnMiH-_B6wg

What’s going on? What have I missed?

How to pass json object from javascript to React Js

I am new to react js. I have a legacy application which is built in Servlet and Jsp. I need to convert a table built in html to datatable using react js. We are particular about react js as the management does not want to use Jquery/Vanilla js datatables.
My first approach was to convert the servlet to a service and make it return json object, however I can’t access the servlet externally (from VS code) due to session management.
So I tried to use CDN approach(react and react-table) within the JSP file using JSX, however I am unable to load react-table in JSX.
Second approach is to convert the array as a json object and pass it to React Js component, however I am not sure how to do this.

Question 1) What is the best approach to convert the html table to react datatable?
Can you provide sample code for this?
Question 2) How to pass json object to React JS?
Can you provide sample code for this?