tablename_dv hook vs. tablename-dv.js

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

tablename_dv hook vs. tablename-dv.js

Post by pfrumkin » 2021-03-26 18:48

Hi All,

General question, are there rules of thumb about when to use the _dv hook and when to use magic .js files when implementing jquery code?

I have used them for the most part interchangeably. A notable exception is when I need data from the hook that isn't easily acquired in the magic file. There are likely more cases like that, and some where it's easier in the .js file. I'm just looking for some ideas for how to decide.

One thought I have is order of operation - which executes first and which takes precedence if there are conflicting statements?

Thanks.

~Paul

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: tablename_dv hook vs. tablename-dv.js

Post by landinialejandro » 2021-03-26 23:17

Hello my friend, from my humble opinion, I think it depends a lot on your js code, on how you have programmed the code and on which elements of the DOM are referenced.
Depending on the above, the .js code can be located almost anywhere.
I think that, if you are going to place a global function (and that also has no effect on the DOM) it should go, for example, in the header_extras.php.
On the other hand, if you are going to work only with a specific form, you would use -dv.js or -tv.js, both files are loaded at the beginning, when loading a form, just after the header_extras. But is loaded only in the specific form.
It can also be placed in foother_extras.php, if what you need is to be sure that the js code is executed at the end, for example to parse the DOM content on any screen.
but there is also the possibility that you need a js code that can mutate depending on some condition and ask the server via ajax to prepare a specific js.
Anyway ... it all depends on what you need to do. It is possible that a js code that you have made may be regardless of where you call it, given its characteristics.
;)
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

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

Re: tablename_dv hook vs. tablename-dv.js

Post by pfrumkin » 2021-03-30 15:39

Thanks Alejandro. I agree about globals, using header_extras and footer_extras. Those are brilliant.

My question is really about the loading sequence and other considerations that would drive to use standalone JS or incorporate into the hooks file. Anyone know if the -dv.js file is loaded before the hooks file? I suspect it is. And does that mean for any conflict the hook file wins because it is loaded last (or -dv.js wins because it is loaded first)?

It's a little klunkier to add JS code in the hooks file. And near as I can tell this only works for DV (hence the hook name), so for JS going into the TV the standalone JS is the only option. But there is some extra power in the hooks file. And if I can use one file for everything rather than two, maybe that's better (maybe not :), depends on coding standards).

~Paul

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

Re: tablename_dv hook vs. tablename-dv.js

Post by pfrumkin » 2021-03-30 20:12

I just did a simple test, found that the -dv.js command will supercede a conflicting command in the _dv hook. I suspect that this means that the hook file runs first, then the -dv.js.

Post Reply