Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Hash cookies global not update

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Hash cookies global not update

Unread post 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..
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Hash cookies global not update

Unread post 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...
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Hash cookies global not update

Unread post 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...
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Hash cookies global not update

Unread post by kev1n »

Hi,

Does this help?

viewtopic.php?p=28608#p28608
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Hash cookies global not update

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Hash cookies global not update

Unread post 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.
Post Reply