Page 1 of 2
hash cookies are not populated on form opening
Posted: Tue Sep 22, 2020 11:10 am
by Hoxen
Hi, I've a problem with building a form that make large use of hash cookies:
The entire form should be dinamically populated on the content of the #form_description# hash cookie.
And everything works just fine if I refresh the page one time after opening it.
But that's also the problem: why the hash cookie that contains the form description is populated only after one refresh?
There is a way the form can use the #form_description# at the first opening?
I see that on the video this problem has been also encoutered for Lookups and solved using nuSetFormValue() to update the values realtime.
Many thanks in advance for any reply.
Re: hash cookies are not populated on form opening
Posted: Tue Sep 22, 2020 3:31 pm
by Hoxen
I can further specify that I'm trying to obtain the #form_description# populated on the form first load on an EDIT form.
Don't hesitate to ask me for any information that may be useful to reach a solution, because I really need that the form content change completely based on a parameter that should not be changed.
I will basically create a copy of the form many times, changing only the form_description in order to change all the content.
Any alternative idea to obtain the same result is welcome.
Re: hash cookies are not populated on form opening
Posted: Tue Sep 22, 2020 5:15 pm
by Janusz
try to place the following code in the: PHP Before Edit; PHP After Save
in my case it works properly - by checking nuDebug (ctrl+shift+d)
and I do not need to perform refresh.
Is it for all objects, for specific objects, how to replicate your case?
FYI: I had some issue with some need for refresh but it was for the browse form:
https://forums.nubuilder.cloud/viewtopic. ... usz#p19321
Re: hash cookies are not populated on form opening
Posted: Wed Sep 23, 2020 8:16 am
by kev1n
Where and how do you set the Hash Cookie?
Re: hash cookies are not populated on form opening
Posted: Wed Sep 23, 2020 2:48 pm
by Hoxen
Janusz wrote:try to place the following code in the: PHP Before Edit; PHP After Save
in my case it works properly - by checking nuDebug (ctrl+shift+d)
and I do not need to perform refresh.
Is it for all objects, for specific objects, how to replicate your case?
Thank you, but your solution don't work.
I tried also to change the form into a "Browse and Edit" one. No luck.
I'll try to better explain my situation:
hash_cookie.jpg
What you see here is now a BROWSE and EDIT form.
All the objects correspond to many SQL queries, and all of them uses the same hash cookie, only one, and that's exactly the #form_description#.
The page is supposed to dinamically update themself only changing the form_description of the form.
This allows me to create more clone pages with different contents.
The image show you the page as it appears at the first load.
Checking nuDebug(), the cookies are populated not at the first launch of the form, but after a refresh, everything's just fine and all the objects are correctly populated with the needed data.
kev1n wrote:Where and how do you set the Hash Cookie?
check out the image, all the fields use it, but only the RUN object is effectively using it at the first load. I don't understand why.
Re: hash cookies are not populated on form opening
Posted: Wed Sep 23, 2020 3:06 pm
by kev1n
Let me rephrase the question:
Where/when is the hash cookie set?
In another form/by clicking a button?
Can you describe which actions are performed before the form is opened?
Re: hash cookies are not populated on form opening
Posted: Thu Sep 24, 2020 8:30 am
by Hoxen
kev1n wrote:Where/when is the hash cookie set?
Uhm, maybe this is the problem. The hash cookies needs to be set?
I supposed that all the form fields, and especially the FORM_DESCRIPTION, that has been declared at the form creation, were loaded and populated automatically at the form opening.
Clearly, after your question... is not what happens.
Yet why the browse table subform is working?
kev1n wrote:Can you describe which actions are performed before the form is opened?
nothing. From the home, the form is loaded. Nothing more.
And after a refresh form, everything works as intended.
Re: hash cookies are not populated on form opening
Posted: Thu Sep 24, 2020 8:46 am
by kev1n
obj.png
Is Team #form_description# a HTML object?
And Assistant + Numero di telefono Display objects?
Re: hash cookies are not populated on form opening
Posted: Thu Sep 24, 2020 9:06 am
by kev1n
This is a workaround, to refresh the Select Objects with some Javascript when the form opens:
Add this code to your form’s Custom Code field. Also replace the Object Ids assistant,numero_di_telefono, team with yours.
Code: Select all
if (nuFormType() == 'edit') {
refreshSelectObject('assistant');
refreshSelectObject('numero_di_telefono');
$('#team').html($('#team').html().replace('#form_description#', nuCurrentProperties().form_description));
}
The function refreshSelectObject() is documented here:
https://github.com/smalos/nuBuilder4-Co ... /README.md
Re: hash cookies are not populated on form opening
Posted: Mon Sep 28, 2020 3:33 pm
by Hoxen
kev1n wrote:Is Team #form_description# a HTML object?
Yes
kev1n wrote:And Assistant + Numero di telefono Display objects?
Yes
Code: Select all
if (nuFormType() == 'edit') {
refreshSelectObject('team_assistant_0');
refreshSelectObject('team_assistant_0_tel');
$('#team').html($('#team').html().replace('#form_description#', nuCurrentProperties().form_description));
}
"Team" text inside the HTML object is plain text to show only, no replacement to be done.
Replacing only assistant and numero_di_telefono with my correspondant field IDs team_assistant_0 and team_assistant_0_tel but the code don't work.
I tried also changing the nuFormType() from edit to browse, nothing changed.
You can see here a list of the objects and their ID in this screenshot:
Cattura.JPG
Thank you for your help so far, anyway.
If you know any other workaround or a fix for this one, will be really welcome.