Editor: Built-in delete message is initially blank

Editor: Built-in delete message is initially blank

rldean1rldean1 Posts: 141Questions: 66Answers: 1
edited April 2018 in Free community support

The first time after the app is opened, and you choose to delete an item, the default built-in delete message is empty.

However, it actually performs the delete. After you choose another row to delete, the delete message is populated appropriately for the rest of the time you use the app.

I tried to create a custom message, and observed the same problem.

Why is that happening?

Much of this code is gleaned from the examples provided:

var editor; // use a global for the submit and return data rendering in the examples

editor = new $.fn.dataTable.Editor({
    //ajax: "../php/staff.php",
    table: "#example",
    fields: [{
        label: "First name:",
        name: "first_name"
    }, {
        label: "Last name:",
        name: "last_name"
    }, {
        label: "Position:",
        name: "position"
    }, {
        label: "Office:",
        name: "office"
    }, {
        label: "Extension:",
        name: "extn"
    }, {
        label: "Start date:",
        name: "start_date",
        type: "datetime"
    }, {
        label: "Salary:",
        name: "salary"
    }
    ]
});

editor.on('preSubmit', function (e, data, action) {

    if (action == 'remove') {
        console.log(e)
        console.log(data)
        console.log(action)
    }

    if (action !== 'remove') {
        var firstName = this.field('first_name');

        if (!firstName.isMultiValue()) {
            if (!firstName.val()) {
                firstName.error('A first name must be given');
            }

            if (firstName.val().length >= 20) {
                firstName.error('The first name length must be less that 20 characters');
            }
        }

        if (this.inError()) {
            return false;
        }

        else {
            console.log("what will be submitted ==>>");
            console.log(data); //The data object that will be submitted to the server

        }

    }
});

editor.on('open', function (e, type) {
    var modifier = editor.modifier();

    if (modifier) {
        var data = table.row(modifier).data();
        console.log("object to be modified ==>>");
        console.log(data);
        // do something with `data`
    }
});


table = $('#example').DataTable({
    dom: "Bfrtip",
    ajax: "./javascript/test_data.txt",
    columns: [
        { data: "first_name" },
        { data: "last_name" },
        { data: "position" },
        { data: "office" },
        { data: "extn" },
        { data: "start_date" },
        { data: "salary", render: $.fn.dataTable.render.number(',', '.', 0, '$') }
    ],
    select: true,
    buttons: [
        { extend: "create", editor: editor },
        { extend: "edit", editor: editor },
        //{ extend: "remove", editor: editor }
        {
            extend: "remove",
            editor: editor,
            formMessage: function (e, dt) {
                var rows = dt.rows(e.modifier()).data().pluck('first_name');
                return 'Are you sure you want to delete the entries for the ' +
                    'following record(s)? <ul><li>' + rows.join('</li><li>') + '</li></ul>';
            }
        }

    ]
});

// Activate an inline edit on click of a table cell
$('#example').on('click', 'tbody td', function (e) {
    editor.inline(this);
});

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @raydlevel5 ,

    That is odd, I just tried it myself here and am unable to reproduce. As you say, the code is moreorless identical to the example, and I even added in your event listeners, so my code is the same as yours.

    It may be something to do with the library files that you're including, possibly the order or the versions? Could you paste them into here please, and I'll try with the same ones that you're using.

    Cheers,

    Colin

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    @colin

    OK, thank you! I'm using the CDN, here's the order:

    <head>, CSS stuff:

        <link rel="stylesheet" href="..\bootstrap-4.0.0\css\bootstrap.min.css">
        
        
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.16/b-1.5.1/r-2.2.1/sl-1.2.5/datatables.min.css"/>
        <link rel="stylesheet" type="text/css" href="./editor-1.7.3/css/editor.dataTables.css">
    
        <style>
            table {
                /* fix problem with borders, DT & BS css */
                border-spacing: 0;
            }
        </style>
    

    <script> stuff, at the end, before </body>:

        <script defer src="https://use.fontawesome.com/releases/v5.0.9/js/all.js" integrity="sha384-8iPTk2s/jMVj81dnzb/iFR2sdA7u06vHJyyLlAd4snFpCl/SnyUjRrbdJsw1pGIl" crossorigin="anonymous"></script>
    
        <script src="..\javascript\jquery-3.2.1.min.js"></script>
    
        <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.16/b-1.5.1/r-2.2.1/sl-1.2.5/datatables.min.js"></script>
        <script type="text/javascript" src="./editor-1.7.3/js/dataTables.editor.js"></script>
    
        <script src="..\bootstrap-4.0.0\js\popper.min.js"></script>
        <script src="..\bootstrap-4.0.0\js\bootstrap.min.js"></script>
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @raydlevel5 ,

    I'm sorry, but I've having no joy in reproducing this. Here's my test case, similar to yours, and everything works as expected. Would you be able to do a live example which demonstrates the problem, please?

    Cheers,

    Colin

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    @colin WOW. Thank you!

    It has something to do with jquery-3.2.1.min.js!! I immediately noticed you're using 1.12.4.js.

    So, I swapped 1.12.4 into my mix, and the delete message worked perfectly. When I put 3.2.1.min.js into your example, it exhibited the same problem I described.

    Looks like they have some later releases, so, I'll try those, and fallback to 1.12.4 if necessary!?

    Thank you for setting up that JS Bin example.

        <!-- <script src="http://code.jquery.com/jquery-1.12.4.js"></script> -->
    <script
      src="https://code.jquery.com/jquery-3.2.1.min.js"
      integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
      crossorigin="anonymous"></script>
    
  • allanallan Posts: 63,441Questions: 1Answers: 10,465 Site admin

    i've just tried your latest live page with jQuery 3.2.1 and it is actually showing the delete message for me. @Colin - could you check if it is working for you or not?

    Allan

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    Definitely not trying to nitpick this (thanks for the help!!). I can change the ver. of my jQuery library as appropriate...

    I'm observing the same scenario:

    1) open the link
    2) don't do anything else (don't press new or edit)
    3) first action: select a row to delete
    4) press delete
    5) delete dialog is blank
    6) select another row to delete; dialog has appropriate message

    side notes: if you choose New, or Edit.... then, later, you choose a row to delete, the delete message is populated...

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ta da - yep, I can see it too with @raydlevel5 's demo :)

    I thought I tried that version, must've got muddled. Good luck with the new versions, shout if we can help in anyway.

    Cheers,

    Colin

  • allanallan Posts: 63,441Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Got it. That was one of the most enjoyable bugs I've looking into in a while (yes, I'm like that!). It looks like in jQuery 1 if you change the display property (or possibly the HTML, I didn't check which) it will automatically stop() any existing animations. jQuery 3 doesn't, and I'd missed a call to stop().

    Adding it in resolves this.

    This will be in 1.7.4. @raydlevel5 - I can send you an updated trial with the fix if you like?

    Thanks,
    Allan

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    @allan We can survive until 1.7.4 comes out!!! Thank you for everything!

  • allanallan Posts: 63,441Questions: 1Answers: 10,465 Site admin

    I think we'll do the 1.7.4 release towards the end of this month. Enough time to allow anything that crops up to be fixed :).

    Allan

This discussion has been closed.