Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Calling Javascript function from GBC form button  (Read 9041 times)
Matthew B.
Posts: 4


« 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.
Reuben B.
Four Js
Posts: 1116


« Reply #1 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


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines