Four Js Development Tools Forum

Discussions by product => GAS and GBC => Topic started by: Matthew B. on August 02, 2021, 03:02:32 am



Title: Calling Javascript function from GBC form button
Post by: Matthew B. on August 02, 2021, 03:02:32 am
If I have a Javascript function defined in a .js file in customization/[project]/js, is there a best-practice way to execute that function from a button widget on a GBC form?

(As opposed to executing a BDL action.)

Preferably where the function name can be defined as an attribute on the button element in the form definition.


Title: Re: Calling Javascript function from GBC form button
Post by: Reuben B. on August 10, 2021, 05:18:34 am
I suspect there is multiple ways and what is best can depend upon some additional factors.

It maybe as simple as customizing/extending the GBC button widget so that it has an onclick attribute.  You can experiment using browser developer tools to add onclick="alert('here')) and seeing that the alert is triggered rather than the 4gl action.. Then you can experiment finding other functions.   It will get interesting if you want to control when the button is active.  You might also consider using LABEL with styles textFormat="html", sanitize="no" instead of a button.

For that last question "... where the function name can be defined as an attribute on the button element in the form definition." ...You do have the TAG attribute http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_FSFAttributes_TAG.html which can be used to pass additional info of your choosing upto the front-end.

Reuben