editor presubmit this.field(field).val() returns empty String

editor presubmit this.field(field).val() returns empty String

pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1
edited April 2020 in Editor

Hi,

when I use this code

 //editor stagiaires en vrijwilligers
    //aanmaken editor
    var editor;
    editor = new $.fn.dataTable.Editor( {
    ajax: "../libraries/Editor/OverzichtMedewerker.php",
    table: "#tableOverzicht",
    fields: [
             
                {
                    label: "datum: ",
                    name: "tbl_VerwerkingTikkingen.VT_Datum",
                    format:'yyyy-mm-dd'
                },
                {
                    label: "Menu: ",
                    name: "tbl_VerwerkingTikkingen.VT_Maaltijdcode",
                    type: "select"
                },
            ]
    } );

    editor.on('preSubmit',function (e,o,action){
        if(action == 'remove' || action == 'edit'){
            let datum=this.field("tbl_VerwerkingTikkingen.VT_Datum");
            let d = new Date();           
           console.log(datum.val()); //returns empty
             let code= this.field("tbl_VerwerkingTikkingen.VT_Maaltijdcode");
console.log(code.val()); //returns the code.           
            let dag = d.getDate();

            //bepalen datum vandaag
            let currentdate = new Date();

            //controle tijdstip opbouwen
            let controllDate = new Date(currentdate.getFullYear(),currentdate.getMonth(),currentdate.getDate(),9,45,0,0);

            //datum object aanmaken van ingegeven datum
            let day  = datum.split("-");
            let orderDate = new Date(parseInt(day[0]),(parseInt(day[1])-1),parseInt(day[2]),currentdate.getHours(),currentdate.getMinutes(),0);
 
           // if ( (datepickerDate<controllDate) || (dag < parseInt(day[0])) ){
            if (controllDate < orderDate && dag ==parseInt(day[2])){
                alert("Je kan voor vandaag niks meer wijzigen");
                return false;
            }
            return false;
        }
    });

    //dataTable
    var table = $('#tableOverzicht').DataTable( {
    dom : 'Bflrtip',
    ajax:"../libraries/Editor/OverzichtMedewerker.php",
    columns: [
             
       { data: "tbl_MaaltijdCodes.MC_Omschrijving" },
       { data: "tbl_VerwerkingTikkingen.VT_Datum" ,
        render: $.fn.dataTable.render.moment( 'DD-MM-YYYY' )         
        },
    ],
    order: [ 1, 'asc' ],
    select: {
        style:    'os',
        selector: 'td:first-child'
    },
    searching: false,
    paging: false,
    info: false,
        buttons: [
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );

returns this an empty string when it should return a date string.

```
let datum=this.field("tbl_VerwerkingTikkingen.VT_Datum");
console.log(datum.val()); //returns empty

if i use this code it returns what i expect.

 ```
 let ds=this.field("tbl_VerwerkingTikkingen.VT_Maaltijdcode");
  console.log(ds.val()); //returns empty

Any idea how it comes?

Answers

  • pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1

    I only have the problem with the remove action, when I use the edit action I can access it.

  • allanallan Posts: 61,665Questions: 1Answers: 10,095 Site admin

    This is expected - the delete action doesn't need the data so the fields don't get populated. Are you looking to be able to reject the delete based on the date? I think you'll need to check the data being submitted directly, which is the second parameter being passed into preSubmit.

    Allan

This discussion has been closed.