Page 2 of 2

Re: Checkbox to set global HK

Posted: Thu Apr 27, 2023 12:33 pm
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?

Re: Checkbox to set global HK

Posted: Thu Apr 27, 2023 2:09 pm
by luca.ongaro
What I did is exactly that. Maybe my JavaScript/PHP need an exorcism. I will make more tests

Re: Checkbox to set global HK

Posted: Thu Apr 27, 2023 2:41 pm
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.

Re: Checkbox to set global HK

Posted: Thu Apr 27, 2023 3:56 pm
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.

Re: Checkbox to set global HK

Posted: Thu Apr 27, 2023 5:42 pm
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.

Re: Checkbox to set global HK

Posted: Fri Apr 28, 2023 8:15 am
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.

Re: Checkbox to set global HK

Posted: Fri Apr 28, 2023 2:17 pm
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...