With form opened, not inline, the submit allIfChanged isn't working on edit

With form opened, not inline, the submit allIfChanged isn't working on edit

daniloragodanilorago Posts: 26Questions: 8Answers: 0

Hello all,

Now I discovered that when I dont edit inline, if I edit via form, the submit "allIfChanged" isn't working. I don't know what I have to do to fix. It's showing error: Warning: Undefined array key "Session__Name" in /home/itxm/public_html/datatables--business-area.php on line 50 ---> LINE 50 oh PHP: Notification__Description' => 'Session "'.$values['Session']['Session__Name'].'" has been updated',

HTML
<!-- ** - - SCRIPT - - ** -->
<script>
addEventListener("DOMContentLoaded", function () {
var editor = new DataTable.Editor( {
ajax: '/datatables--session.php',
table: '#DT__List',
formOptions: {
main: {
focus: null,
submit: 'changed'
}
},
fields: [
{
"label": "ID__Session:",
"name": "Session.ID__Session",
"type": "readonly",
"attr": {
"disabled": true
}
},
{
"label": "ID__Project:",
"name": "Session.ID__Project",
"type": "select",
"placeholder": "Select the project!",
"def": <?php echo $_SESSION["ID__Project"]; ?>,
"attr": {
"disabled": true
}
},
{
"label": "ID__Fit_Gap__Workstream:",
"name": "Session.ID__Fit_Gap__Workstream",
"type": "select",
"placeholder": "Select the workstream!"
},
{
"label": "Session__Location:",
"name": "Session.Session__Location",
"type": "text",
"attr": {
"maxLength": 100
}
},
{
"label": "Session__Name:",
"name": "Session.Session__Name",
"type": "text",
"attr": {
"maxLength": 100
}
},
{
"label": "Session__Initial_Workshop_Date:",
"name": "Session.Session__Initial_Workshop_Date",
"type": "datetime",
"format": "YYYY-MM-DD"
},
{
"label": "Session__Final_Workshop_Date:",
"name": "Session.Session__Final_Workshop_Date",
"type": "datetime",
"format": "YYYY-MM-DD"
},
{
"label": "Session__Date:",
"name": "Session.Session__Date",
"type": "readonly",
"attr": {
"disabled": true
}
},
{
"label": "ID__Login:",
"name": "Session.ID__Login",
"type": "readonly",
"attr": {
"disabled": true
}
}
]
} );

var table = new DataTable('#DT__List', {
ajax: '/datatables--session.php',
columns: [
{
"data": "Session.ID__Session"
},
{
"data": "Project.Project__Name",
"editField": "Session.ID__Project"
},
{
"data": "Fit_Gap__Workstream.Fit_Gap__Workstream__Name",
"editField": "Session.ID__Fit_Gap__Workstream"
},
{
"data": "Session.Session__Location"
},
{
"data": "Session.Session__Name"
},
{
"data": "Session.Session__Initial_Workshop_Date"
},
{
"data": "Session.Session__Final_Workshop_Date"
},
{
"data": "Session.Session__Date"
},
{
"data": "Login.Login__Name",
"editField": "Session.ID__Login"
},
{
data: null,
orderable: false,
"render": function (data, type, row, meta){
return '<a href="<?php echo $Str__User__Setup__Link_Painel; ?>consult-session-backup/'+data.Session.ID__Session+'" target="_blank"><i class="btn btn-icon btn-sm bx bx-category"></i></a>';
}
}
],
colReorder: true,
fixedColumns: {
start: 1
},
fixedHeader: true,
layout: {
bottom: 'searchBuilder',
topStart: {
buttons: [
{
extend: 'create',
text: '<i class="fa fa-plus"></i> Add',
className: 'btn btn-outline-primary btn-wave',
editor: editor
}, {
extend: 'edit',
text: '<i class="fa fa-edit"></i> Edit',
className: 'btn btn-outline-primary btn-wave',
editor: editor
}, {
extend: 'remove',
text: '<i class="fa fa-trash"></i> Delete',
className: 'btn btn-outline-primary btn-wave',
editor: editor
}, {
extend: 'colvis',
text: '<i class="fa fa-search"></i> Columns',
className: 'btn btn-outline-primary btn-wave',
dropIcon: false,
editor: editor
}, {
extend: 'collection',
text: '<i class="fa fa-file-export"></i> Export',
className: 'btn btn-outline-primary btn-wave',
buttons: ['copy', 'excel', 'csv', 'pdf', 'print'],
dropIcon: false
}
]
}
},
order: [[0, 'desc']],
pageLength: 20,
paging: true,
scrollX: true,
scrollY: 550,
select: {
attr: {
className: 'selected-row'
},
selector: 'td:first-child'
}
});
editor.on('submitSuccess', () => {
$('#DT__List').DataTable().ajax.reload();
});
// >>> UPDATE
table.on('click', 'tbody td:not(:first-child)', function (e) {
editor.inline(this, {
onBlur: 'submit',
submit: 'allIfChanged'
});
});
});
$.extend( true, DataTable.Buttons.defaults, {
dom: {
container: {
className: 'btn-group'
},
button: {
className: 'btn btn-secondary'
},
collection: {
tag: 'div',
className: 'dropdown-menu',
closeButton: false,
button: {
tag: 'a',
className: 'dropdown-item',
active: 'active text-white',
disabled: ''
}
},
splitWrapper: {
tag: 'div',
className: '',
closeButton: false
},
splitDropdown: {
tag: 'button',
text: '',
className: 'btn btn-secondary',
closeButton: false,
align: 'split-left',
splitAlignClass: 'dt-button-split-left'
},
splitDropdownButton: {
tag: 'button',
className: 'btn btn-secondary',
closeButton: false
}
},
buttonCreated: function ( config, button ) {
return config.buttons ?
$('<div class="btn-group"/>').append(button) :
button;
}
} );
</script>
--------------------------------------------------------------------------------
PHP

ob_start();
include("DataTables/php/lib/DataTables.php");
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

function Fc__Notification($db, $action, $id, &$values){
    if($action=='create'){
        $db->insert('Notification', array(
            'ID__Login'                 => $_SESSION["ID__Login"],
            'Notification__ID'          => $id,
            'Notification__Table'       => 'Session',
            'Notification__Action'      => '3',
            'Notification__Date'        => date("Y-m-d"),
            'Notification__Title'       => 'Created Session',
            'Notification__Description' => 'Session "'.$values['Session']['Session__Name'].'" has been created',
            'Notification__Status'      => '1'
        ));
    }elseif($action=='delete'){
        $db->insert('Notification', array(
            'ID__Login'                 => $_SESSION["ID__Login"],
            'Notification__ID'          => $id,
            'Notification__Table'       => 'Session',
            'Notification__Action'      => '2',
            'Notification__Date'        => date("Y-m-d"),
            'Notification__Title'       => 'Deleted Session',
            'Notification__Description' => 'Session "'.$values['Session']['Session__Name'].'" has been deleted',
            'Notification__Status'      => '1'
        ));
    }elseif($action=='edit'){
        $db->insert('Notification', array(
            'ID__Login'                 => $_SESSION["ID__Login"],
            'Notification__ID'          => $id,
            'Notification__Table'       => 'Session',
            'Notification__Action'      => '1',
            'Notification__Date'        => date("Y-m-d"),
            'Notification__Title'       => 'Updated Session',
            'Notification__Description' => 'Session "'.$values['Session']['Session__Name'].'" has been updated',
            'Notification__Status'      => '1'
        ));
    }
}

Editor::inst($db, 'Session', 'ID__Session')
    ->fields(
        Field::inst('Session.ID__Session')->set(false),
        Field::inst('Session.ID__Project')
            ->options(
                Options::inst()
                    ->table('Project')
                    ->value('ID__Project')
                    ->label('Project__Name')
            )
            ->validator(Validate::notEmpty(ValidateOptions::inst()
                ->message('Error: Fill the Project field!')
            ))
        ,
        Field::inst('Project.Project__Name'),
        Field::inst('Session.ID__Fit_Gap__Workstream')
            ->options(
                Options::inst()
                    ->table('Fit_Gap__Workstream')
                    ->value('ID__Fit_Gap__Workstream')
                    ->label('Fit_Gap__Workstream__Name')
            )
            ->validator(Validate::notEmpty(ValidateOptions::inst()
                ->message('Error: Fill the Workstream field!')
            ))
        ,
        Field::inst('Fit_Gap__Workstream.Fit_Gap__Workstream__Name'),
        Field::inst('Session.Session__Location'),
        Field::inst('Session.Session__Name'),
        Field::inst('Session.Session__Initial_Workshop_Date'),
        Field::inst('Session.Session__Final_Workshop_Date'),
        Field::inst('Session.Session__Date')->setValue(date("Y-m-d")),
        Field::inst('Session.ID__Login')->setValue($_SESSION['ID__Login'])
            ->options(
                Options::inst()
                    ->table('Login')
                    ->value('ID__Login')
                    ->label('Login__Name')
            )
            ->validator(Validate::notEmpty(ValidateOptions::inst()
                ->message('Error: Fill the Login field!')
            ))
        ,
        Field::inst('Login.Login__Name')
    )
    ->leftJoin('Project', 'Project.ID__Project', '=', 'Session.ID__Project')
    ->leftJoin('Fit_Gap__Workstream', 'Fit_Gap__Workstream.ID__Fit_Gap__Workstream', '=', 'Session.ID__Fit_Gap__Workstream')
    ->leftJoin('Login', 'Login.ID__Login', '=', 'Project.ID__Login')
    ->on('postCreate', function($editor, $id, &$values, &$row){
        Fc__Notification($editor->db(), 'create', $id, $values);
    })
    ->on('postEdit', function($editor, $id, &$values, &$row){
        Fc__Notification($editor->db(), 'edit', $id, $values);
    })
    ->on('preRemove', function($editor, $id, &$values){
        Fc__Notification($editor->db(), 'delete', $id, $values);
    })
    ->process($_POST)
    ->json();
ob_end_flush();

Somebody knows what to do?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,913Questions: 26Answers: 5,063

    You have this:

    formOptions: {
    main: {
    focus: null,
    submit: 'changed'
    }
    },
    

    The formOptions docs show that this is setting the main editing form. The form-options submit docs state this for changed:

    changed - Only the values of the fields that have been changed will be submitted

    Change the config to use allIfChanged if you want to submit all the edit fields.

    Kevin

  • daniloragodanilorago Posts: 26Questions: 8Answers: 0

    Hello @kthorngren

    It's like that, on line 183:

    table.on('click', 'tbody td:not(:first-child)', function (e) {
      editor.inline(this, {
        onBlur: 'submit',
        submit: 'allIfChanged'
      });
    });
    
  • kthorngrenkthorngren Posts: 21,913Questions: 26Answers: 5,063
    Answer ✓

    The code on line 183 is specifically for inline editing. The code on line 8 is configuring the main edit form, for example when using the Edit or Create buttons. Please read the formOptions docs for more details.

    If you want the main editor form to send all fields then change line 12 to submit: 'allIfChanged'.

    Kevin

  • daniloragodanilorago Posts: 26Questions: 8Answers: 0

    Now I got your point, thanks a lot Kevin, it's working!

Sign In or Register to comment.