Page 1 of 1

Subform not saving

Posted: Sat Mar 17, 2018 2:20 pm
by tonyd
I have a subform
subform.jpg
whose parent has the following code:

Code: Select all

if(nuFormType() == 'browse'){
    nuShowBrowseImages()
}else{
    nuShowFile();
}




function nuBeforeSave(){

    $('[data-nu-table="Docs"]').each(function(index,item){
        if (item.children[2].classList.contains("nuEdited")){

            var j = JSON.parse(item.children[2].value);
            var d = Date.now();

            item.children[5].value = j.name; //'File Name' column
            item.children[4].value = Date(d);//'Last Modified' column
            nuHasBeenEdited();
        }
    });
   

    return true;

}


function nuShowFile(){
   $('[data-nu-table="Docs"]').each(function(index){

        var t = $(this)[0].children;
        if (t[1].value !== '') {
            
            $.ajax({
                url: 'https://' + window.location.hostname + '/upload-target/' + t[5].value,
                method: 'GET',
                xhrFields: {
                    responseType: 'blob'
                },
                success: function (data) {
                    var ur = window.URL.createObjectURL(data);
                    var x   = document.createElement("EMBED");
                    var ty = data.type
                    x.setAttribute("type", ty);
                    x.setAttribute("src", ur);
                    x.setAttribute("width", "140px");
                    x.setAttribute("height", "140px");
                    
                    t[0].innerHTML = '';
                    t[0].appendChild(x);
                },
                error: function(data) {
                    alert("Failed to get file")
                }
            });
        }
   });
}


function nuShowBrowseImages(){
    //console.log($('[data-nu-column="0"]')[0].innerText);
}
As you can see, I have some code to set two of the column values if the file selection has been modified. The problem comes when I click the 'save' button on the parent form the values return to the original. I cannot seem to find where this would be fixed. I am sure it is something simple.

Re: Subform not saving

Posted: Sat Mar 17, 2018 4:24 pm
by tonyd
Figured it out! I added a couple of lines to append the "nuEdited" class to each column's element.

Code: Select all

item.children[4].classList.add('nuEdited');
item.children[5].classList.add('nuEdited');
All is right with the world. :D

Re: Subform not saving

Posted: Sat Mar 17, 2018 5:46 pm
by admin
.