field().multiSet() with html5 date field
field().multiSet() with html5 date field
I am having an issue with field().multiSet() and html5 date field. In my dataTables I created html5 date fields like this:
{
data: "work.dateTimePlaced",
"render": function ( data, type, full, meta ) {
return '<input type="date" class="form-control" name="dateTimePlaced" id="dateTimePlaced_'+full.work.work_id+'">';
},
orderable: false
}
Then I extended the button plugin to allow one click submit of all selected rows with help from this forum post: https://datatables.net/forums/discussion/36459/customized-control-button-modification#latest. All works well if all the dates are the same. If I have differing dates the form does not get submitted. Here is my extend button code:
buttons: [
{ extend: "edit", editor: editor6 }
,
{
extend: "selected",
text: "Submit Selected Row(s)",
action: function ( e, dt, node, config ) {
var rows = request_count_table.rows( { selected: true } ).indexes();
editor6.edit( rows, false );
$.each( rows, function (i, rowIdx) {
var row = request_count_table.row( rowIdx );
var ir = row.id().replace('row_','');
//these are inline elements in datatables
var pri = document.getElementById("priority_"+ir).value;
var dat = document.getElementById("dateTimePlaced_"+ir).value;
var cri = document.getElementById("criticalityNumber_"+ir).checked?"Yes":"No";
var dateFormat = "YYYY-MM-DD";
console.log(dat);
/* console.log(ir);
console.log(pri);
console.log(dat);
console.log(cri);*/
//console.log(moment(dat, dateFormat, true).isValid());
if(moment(dat, dateFormat, true).isValid() === false){
swal({title:"Error!", text: "Please select a date!", type: "error"});
return false;
}
editor6.field( 'work.priority' ).multiSet( row.id(), pri );
editor6.field( 'work.dateTimePlaced' ).multiSet( row.id(), dat );
editor6.field( 'work.criticalityNumber' ).multiSet( row.id(), cri );
});
editor6.submit();
//after submit
editor6.on( 'submitComplete', function ( e, json,data ) {
//console.log(json.error);
if(!!json.error){
swal({title:"There was an error!", text: json.error, type: "error", html: true});
}
});
}
}
]
When the dates are different I get no error but the form is not submitted. Any thoughts?
This question has an accepted answers - jump to answer
Answers
php/lib/Database/Driver/Mysql/Query.php has a line for logging sql statements to a file.
You might find some info by checking what you're actually sending out.
Thank you so much for that tip.
It would also be interesting to know if the Ajax request is actually made or not. If it is, what is the data that is being submitted to the server-side? Your browser's network tools will be able to show you that.
Allan
From my examination no request is made to the server when different dates are given and no exception is thrown by Javscript. All those console.log() return values which indicate that the code block is actually running but it appears editor6.submit(); is not running. How can I fix this?
Can you give me a link to the page showing the issue so I can debug it please? If that isn't possible and you show me your full Javascript initialisation for DataTabled and Editor.
Thanks,
Allan
Hello Allan,
Here goes:
The problem might be
row.id()
. Could you try:row.id(false)
please?Also, at lines
128
and161
in the above could you add:please and let me know what the output is.
Thanks,
Allan
Hi Allan,
I have tried what you said and this is what was returned. The first block is from line 128 console log and the second block is from line 161 console log.
The form did not submit at first and showed no error when the dates are different but when they are the same it is submitted as previously reported. After further investigation of my code I got it to work . Thank you so much for your help.
Did you try the
row.id(false)
? Without thatid()
will return the id with a#
prefix causing the id to be incorrect relative to what Editor is seeing (row_91
for example).Very weird. So it gets as far as executing the
submit()
call, but there is no error and no Ajax request?I really think I'm going to need to be able to view the page so I can debug and trace the code through to see why that is happening.
Allan