Set Web Property with a Client-Side event

From DataFlex Wiki
Revision as of 11:37, 3 March 2020 by Wil (talk | contribs) (Created page with " This is a topic based on a forum post (archiving it here so that it is easier to find back) [")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This is a topic based on a forum post (archiving it here so that it is easier to find back)

Set Web Property with Javascript

Harm's example code:

Object oMyForm is a cWebForm
    { WebProperty=Client }
    Property Integer piFocusCount 0
    Set psClientOnFocus to "window.OnFocusIncrementCount"
    Set piColumnSpan to 12
    Set psLabel to "Counts focus:"

Object oMyButton is a cWebButton
    Set piColumnSpan to 0
    Set psCaption to "button"

    Procedure OnClick
        Integer iCount
        WebGet piFocusCount of oMyForm to iCount
        Send ShowInfoBox (SFormat("Form was focussed %1 times!", iCount))

And the OnFocusIncrementCount JavaScript implementation:

function OnFocusIncrementCount(oEvent){
    var oMyForm = oEvent.oSource;
    var iCount = oMyForm.get("piFocusCount");
    oMyForm.set("piFocusCount", iCount);

With the psClient.. event handlers you can define your functions globally (like in the example above) or locally on the object or subclass. If the event is defined globally then this will refer to the object on which the function is defined (in this case window). But the event always gets an event object as parameter with several properties including the source object of the event (oSource). So in the example above oSource points to the JavaScript version of oMyForm. Web properties can be accessed directly, but better is to use the get and set functions. The set function will make the property synchronized (so that is value is sent to the server) and both functions can take care of type conversions.

   Harm Wibier
   Data Access Europe B.V.