Welcome to the nuBuilder Forums!

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

Checkbox to set global HK

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Checkbox to set global HK

Unread post by kev1n »

I don't seem to be able to replicate this.

I set a global HK:

Code: Select all

nuSetProperty('hk', nuGetValue('mycheckbox').toString(), true)
(HK is set to either "true" or "false".)

Next, in a Browse SQL, I added the following SQL code:

Code: Select all

SELECT * FROM mytable where my_column <> '#hk#'
However, when I inspect the generated SQL, the HK variable is always replaced with either "true" or "false", even when I navigate to another page on the Browse form.

I also added in BB:

Code: Select all

nuDebug('#hk#');
and nuDebug Results also shows "true" or "false", never 0, 1.


Are you doing anything differently that I should know about?
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: Checkbox to set global HK

Unread post by luca.ongaro »

What I did is exactly that. Maybe my JavaScript/PHP need an exorcism. I will make more tests
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: Checkbox to set global HK

Unread post by luca.ongaro »

hmmm...
I used this line to set a global HK

Code: Select all

nuSetProperty('chkbox_inq_tutti',nuGetValue('chkbox_inq_tutti').toString(), true);
using for the HK the same name of the checkbox, and my application works, using an OR to manage "0/1" vs. "true/false".
If I change it into, for example:

Code: Select all

nuSetProperty('hk',nuGetValue('chkbox_inq_tutti').toString(), true);
then

Code: Select all

nuDebug('#hk#');
returns the string #hk# (and of course everything stop working).
Frankly speaking, I am confused.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Checkbox to set global HK

Unread post by kev1n »

That's odd indeed.

To replicate the process, kindly provide me with details on the location and method of setting the hash cookie, as well as the location where it is retrieved. For instance, if the hash cookie is set on an edit form, or triggered by the onblur event of a specific element, and retrieved in the BB event etc.
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: Checkbox to set global HK

Unread post by luca.ongaro »

I have three forms that are run from nuuserhome. Each of them has its button and its checkbox to change the form's browse SQL.
An HK is set when the user click a button (onClick event) in nuuserhome to open a form, according to the corresponding checkbox.
At that point the HK is retrieved by the BB code of the forms.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Checkbox to set global HK

Unread post by kev1n »

It appears that the issue at hand is related to timing, likely due to the asynchronous nature of function calls. Specifically, it seems that the form is being opened prior to the hash cookie being set.

To resolve this, one potential solution would be to replace the existing run button with an input button that has an onclick function calling nuSetProperty(). Then, in the custom code section of the form, you can declare a nuOnPropertySet() function.

For a detailed example, please refer to the following link: viewtopic.php?p=28571#p28571.
luca.ongaro
Posts: 64
Joined: Sun Jan 22, 2023 7:03 pm

Re: Checkbox to set global HK

Unread post by luca.ongaro »

Got it. Asynchronous behaviour of nuSetProperty() is more than tricky!
Apparently, I solved the problem getting back to my first approach, i.e. setting the HK using onChange event of the checkbox.
Setting HK for a form from its run button should be simply deprecated.
Thank you once again, kev1n...
Post Reply