Page 1 of 1

Hash cookies global not update

Posted: Sat Aug 19, 2023 1:08 pm
by calida82
i am using this custom code to be able to add 2 icons to each browse module to be able to switch from one browse module to another browse module connected to it by use of global hash cookies, but sometimes this seems not to work in the sense that sometimes the cookies hash variable is not updated and in the second browse module you are shown wrong data. this scares me because it endangers the integrity of the data...
why does this happen?

Code: Select all

// No action when clicking a cell
function nuSelectBrowse(e) {
    return false;
}

function createButton(target, pk, label, title, openAction) {

    let btn = $('<button type="submit" style="padding-top: 2px; height:27px; border: none; vertical-align: center; background-color: #378bd5; transform: translateY(-10%); color:white">'+ label +'</button>');

    $(target).html(btn).attr('title', nuTranslate(title));
    
    btn.on('click', function() {
        openAction(pk);
    });
}

function addButons(column, label, title, openAction) {

    $("[data-nu-column='" + column + "']").each(function(index) {
        var pk = $(this).attr('data-nu-primary-key');
        if (typeof pk !== "undefined") {
            createButton(this, pk, label, title, openAction);
        }
    })

}

function openEditForm(pk) {
    nuForm(nuGetProperty('form_id'), pk, '', '', '0');   
}

function openBrowseForm(pk) {
    nuSetProperty('pk_cliente',pk,true);  
    nuForm('64da2a46ca706af', '', '', '', '0');
    
    

      
}

// Add an edit and browse button
// Icon list: https://fontawesome.com/v5/search?m=free
addButons(1, '<i class="fa fa-pencil"></i>', 'Modifica', openEditForm);
addButons(0, '<i class="fa fa-search"></i>', 'Elenco', openBrowseForm);

if i put this code in the second browse module connected to the first one

Code: Select all

function nuOnLoad(){
   if(nuFormType() == 'browse'){
      console.log(nuGetProperty('pk_cliente'));
   }
}
in the code of the browse module connected from the log I can see that sometimes the code reported is that of the previous client viewed..

Re: Hash cookies global not update

Posted: Sat Aug 19, 2023 2:27 pm
by calida82
i noticed one thing, i developed the application on my linux notebook with nubuilder installed in an lxc container and here it seems to work fine. I did a baskup of the database from nubuilder and moved to an MSI mini pc with intel celeron 3050 processor and 4gb of ram with ubuntu server installed and here it gives me the problems updating the variables. Is it possible that the mini pc can't run apache + mysql properly?. on this same pc the same application made with oracle application express ran without the slightest delay...

Re: Hash cookies global not update

Posted: Sat Aug 19, 2023 2:51 pm
by calida82
I don't understand, if I add nuMessage to be able to see if the variable has changed value before opening the new form

Code: Select all

function openBrowseForm(pk) {
    nuSetProperty('pk_cliente',pk,true); 
    nuMessage(nuGetProperty('pk_cliente'));
    nuForm('64da2a46ca706af', '', '', '', '0');
}
when I promote on the button the code displayed in the message is always correct even when the module is opened with the values ​​of the previous one and if I do the console.log on the second module the variable does not seem to have changed its value...

Re: Hash cookies global not update

Posted: Sat Aug 19, 2023 4:40 pm
by kev1n
Hi,

Does this help?

viewtopic.php?p=28608#p28608

Re: Hash cookies global not update

Posted: Sat Aug 19, 2023 8:22 pm
by calida82
Hi, I think I fixed it this way

Code: Select all

function openBrowseForm(pk) {
    nuSetProperty('pk_cliente',pk,true); 
    nuMessage(nuGetProperty('pk_cliente'));
    setTimeout( () => nuForm('64da2a46ca706af', '', '', '', '0'),500);
      
}
I thought it was a delay problem because in my notebook everything worked I had already tried the setTimeout function but not knowing java I used it the wrong way and therefore it didn't work,

Code: Select all

setTimeout( nuForm('64da2a46ca706af', '', '', '', '0'),5000)
even setting a 5 second delay the page opened immediately. then looking a bit on the setTimeout function I understood how it was used.
another thing I wanted to ask you, the nuOnLoad function should be used in the custom code of each module and is it referred only to that module?
I'm asking because in the custom code function of the second module I had used this function to check the value of the cookie hash in the console, but I saw that the log was also executed when I returned from the second module to the first via breadcrums. so I don't understand if the function is valid for all modules and if it should be inserted in the custom code

Re: Hash cookies global not update

Posted: Mon Aug 21, 2023 10:42 pm
by kev1n
nuOnLoad() can only be used in Setup->Header. In a form's custom code, it is not triggered.
I'm wondering if you could try out nuOnPropertySet()? I posted a link to another topic above.