Editor editing issue? Can edit text, but not clear the text.

Editor editing issue? Can edit text, but not clear the text.

boicenetboicenet Posts: 47Questions: 12Answers: 1
edited October 2016 in Free community support

I'm using Datatables with the New, Edit, Delete buttons. I can select a row and Edit the displayed data (replace content with new content) and the changes are Updated to the database. However, when I Edit the same row (or any other row) and clear a field's text by deleting all of the existing text in the field, the Update change is not saved to the database. Can anyone advise me on how to correct this issue? Note: if I delete all of the text and instead replace it with one press of the spacebar, I can get the text to be removed from the database (and replaced with the space).

Replies

  • allanallan Posts: 61,623Questions: 1Answers: 10,090 Site admin

    Can you show me your server-side code please? I'm not immediately sure why that would be, but it sounds like the server is ignoring the field if it is being submitted as an empty value (which should be perfectly legal and valid, as you will be able to see it working in the Editor examples).

    Allan

  • boicenetboicenet Posts: 47Questions: 12Answers: 1

    Here is the code. I'm trying to clear the text in 'machine_desc'.

    -Thanks.

    // DataTables PHP library
    include( "MachineTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'machines', 'machine_id' )
        ->fields(
            Field::inst( 'machine_name' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'machine_desc' ),
            Field::inst( 'machine_colors' )
        )
        ->process( $_POST )
        ->json();
    
    
  • allanallan Posts: 61,623Questions: 1Answers: 10,090 Site admin

    That's very odd. Can you also show me the client-side code? Could you also confirm if it works in my examples for you (it does appear to work okay for me)?

    Thanks,
    Allan

  • boicenetboicenet Posts: 47Questions: 12Answers: 1

    I will not be surprised if I caused my own problem. Still in learning mode.

    Here is my client side js.

    <script type="text/javascript" language="javascript" class="init">
    
    
            $(document).ready(function() {
                editor = new $.fn.dataTable.Editor( {
                    ajax: "machines.php",
                    table: "#machine_table",
                    fields: [
                        {
                            label: "Machine Name",
                            name: "machine_name"
                        }, {
                            label: "Description",
                            name: "machine_desc"
                        }, {
                            label: "Colors",
                            name: "machine_colors"
                        }
                    ],
    
                    i18n: {
                        create: {
    
                            title:  "Add New Machine"
                        },
                        edit: {
    
                            title:  "Edit Machine Details"
                        },
                        remove: {
    
                            title:  "Delete Selected Machine?"
    
                        }
                    }
    
                } );
    
    
                $('#machine_table').DataTable( {
                    "iDisplayLength": 12,
                    dom: "Bfrtip",
                    ajax: "machines.php",
                    columns: [
                        { data: "machine_name"},
                        { data: "machine_desc" },
                        { data: "machine_colors" }
                    ],
                    select: true,
                    buttons: [
                        { extend: "create", editor: editor },
                        { extend: "edit",   editor: editor },
                        {
                            extend: "remove",
                            editor: editor,
                            formMessage: function ( e, dt ) {
                                var rows = dt.rows( e.modifier() ).data().pluck('machine_name');
                                return 'Are you sure you want to permanently delete this machine? <ul><li>'+rows.join('</li><li>')+'</li></ul>';
                            }
                        }
                    ]
                } );
    
            } );
    
        </script>
    
    
  • boicenetboicenet Posts: 47Questions: 12Answers: 1

    I ran the simple bubble-editing example on my server and it works well. I used the Editor-PHP-1.5.6 folder to do so. Since my code is in a separate folder, I'm wondering if I'm missing some important file in my path.

  • boicenetboicenet Posts: 47Questions: 12Answers: 1

    Allan,

    In my HTML file I am now referencing the following js. I used the Download Builder tool at datatables.net and if I recall correctly chose just about everything.

    I took the js references from the simple.html file example for simple bubble-editing (which works on my server) and replaced my download builder version with the following references. I could no longer display my data when I did this.

    When I added my download builder version beneath the following group I could then again display data, but still could not edit. I'm not sure if this helps at all.

        <script type="text/javascript" language="javascript" src="assets/vendor/resources/jquery-1.12.3.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/jquery.dataTables.min.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/dataTables.buttons.min.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/dataTables.select.min.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/dataTables.editor.min.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/syntax/shCore.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/demo.js">
        </script>
        <script type="text/javascript" language="javascript" src="assets/vendor/resources/editor-demo.js">
        </script>
    
    
        // My Download Builder version.
        <script type="text/javascript" src="assets/vendor/dt/datatables.js"></script>
    
    
  • boicenetboicenet Posts: 47Questions: 12Answers: 1

    Allan,

    I used Download Builder to create another css/js file. Still getting the same results where I cannot clear a text field using Datatables and Editor. Not sure what else to check.

  • allanallan Posts: 61,623Questions: 1Answers: 10,090 Site admin

    This gets odder and odder! Everything you have done looks right to me!

    Are you able to PM me a link to the page so I can check it out and attempt to debug it live? To send me a PM click my name above and then "Send message".

    Thanks,
    Allan

  • boicenetboicenet Posts: 47Questions: 12Answers: 1
    edited November 2016

    FYI...

    I updated the Suhosin Php extension as recommended by Allan and that resolved the issue.


    Hi Bob,

    What I did to find out what was going on was to add:

        print_r( $_POST );
    

    as the very first line in the file Editor sends the Ajax edit request to. It showed that anything that was submitted with an empty string was being stripped out before any of the user space code ran. That meant it had to be PHP itself or a plug-in. I'm not aware of any PHP config option that would cause that and the issue link linked to for suhosin indicates that the error is there - your server is running exactly the same version as they indicate is buggy (0.9.36).

    Regards,
    Allan

This discussion has been closed.