Hidden field's value get overwritten when updating record

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Hidden field's value get overwritten when updating record

Post by devedix » 2021-05-26 06:42

Hi all,
I've created a table with some hidden fields (it doesn't show in table view and detail view) and automatically populated it within the tablename_before_insert function, the function works just fine when I created a new record.
But when I updated the record and save it, the hidden field's value gets overwritten and becomes null.
Can anyone help with this problem?
Thanks
Regards,
Edix

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Hidden field's value get overwritten when updating record

Post by pfrumkin » 2021-05-26 17:23

Hi Edix,

Are you manually setting those column values using SQL in the insert hook? It is possible that the hidden values are still represented in the $data structure in the update hook, so by not setting it explicitly in the update hook, it is null and that is what is getting updated. Whatever you do to set the value in the insert, apply that in the before_update hook.

~Paul

devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Re: Hidden field's value get overwritten when updating record

Post by devedix » 2021-05-27 14:17

Hi Paul,
I've found a workaround for this problem, I unhide the field in appgini and then hide it using jquery.
Maybe just like you said, the before_update set it to null.
Regards,
Edix

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Hidden field's value get overwritten when updating record

Post by onoehring » 2021-05-29 08:20

Hi,

if you hide fields in AG, they are not included in the $data e.g. in the _before_insert function.
Instead making fields visible in AG - you probably do not want people to be able to see those fields (which would essentially be possible using the console of the browser, when using jquery), I suggest the following: Use the tablename_after_insert to access the record in the database directly and then write the data you want to add to the "hidden" field. This way, no one would be able to interfere with the data. IN the after_insert just grab the $selectedID from the $data variable $data('selectedID') and use your own SQL to update the specific record.

Olaf

devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Re: Hidden field's value get overwritten when updating record

Post by devedix » 2021-06-01 08:32

Hi Olaf,
Thanks for the explanation, I will try it and update the result as soon as I can.
Regards,
Edix

Post Reply