Changed the code to use the jquery change() function.
Code: Select all
function nuBeforeSave(){
$('[data-nu-table="Docs"]').each(function(index,item){
if (item.children[2].classList.contains("nuEdited") && item.children[2].value !== ''){
var ma = item.children[1].id;
var da = item.children[4].id;
var fn = item.children[5].id;
var j = JSON.parse(item.children[2].value);
var d = Date.now();
$('#' + ma).val(item.attributes['data-nu-foreign-key'].value).change(); //holds mattersid
$('#' + da).val(Date(d)).change(); //'Last Modified' field
$('#' + fn).val(j.name).change(); //'File Name' field
}
});
return true;
}
FYI, I have changed the nuChangeFile() function to save the file to the server instead of the database:
Code: Select all
function nuChangeFile(e){
if(e.target.id.substr(-8) == 'nuDelete'){
nuHasBeenEdited();
return;
}
var theFile = e.target.id;
var theTextarea = theFile.substr(0, theFile.length - 5);
if($('#' + theFile).val()==''){return;}
var a = $('#' + theFile)[0].files[0];
var r = new FileReader();
r.onload = function(e) {
var f = r.result; //don't really need this because we no longer
//save file contents to the database
var o = {'file' : '', 'name' : a.name, 'size' : a.size, 'type' : a.type};
var j = JSON.stringify(o);
$('#' + theTextarea).val(j).addClass('nuEdited');
// create a form and load our file onto it
var formdata = new FormData();
formdata.append("files[]", a);
$.ajax({ //-- save file to server
url: "/nuuploader.php",
type: "POST",
data: formdata,
processData: false,
contentType: false, // this is important!!!
success: function (D,S,T) {
// should do some error checking here
// reset formdata
formdata = false;
},
error: function (X,S,T) {
alert("Upload Failed: " + X);
}
});
}
r.readAsBinaryString(a); //-- use a binary read instead of text
var t = $('#' + theFile)[0];
var p = $('#' + theTextarea).attr('data-nu-prefix');
$('#' + p + 'nuDelete').prop('checked', false);
$('#' + theTextarea).addClass('nuEdited');
nuHasBeenEdited();
if(p == ''){return;}
nuAddSubformRow(t, e);
}
I get this nuDebug error message
error.jpg
I can see the field values change briefly in the subform before the save, but then the new fields goes blank again. I think the code looks cleaner this way, but it still doesn't work.
You do not have the required permissions to view the files attached to this post.