Subform not saving

Questions related to using nuBuilder Forte.

Subform not saving

Postby tonyd » Sat Mar 17, 2018 10:50 pm

I have a subform

subform.jpg
subform.jpg (29.05 KiB) Viewed 147 times

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.
TonyD
tonyd
 
Posts: 68
Joined: Mon Mar 05, 2018 3:08 am

Re: Subform not saving

Postby tonyd » Sun Mar 18, 2018 12:54 am

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
TonyD
tonyd
 
Posts: 68
Joined: Mon Mar 05, 2018 3:08 am

Re: Subform not saving

Postby admin » Sun Mar 18, 2018 2:16 am

.
admin
Site Admin
 
Posts: 2971
Joined: Mon Jun 15, 2009 9:53 am


Return to General



cron