CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Event Handling

Here you can find some answers to your questions, and also some tutorials.

by Jorge Sousa » 20 Jun 2012 16:44

To handle javascript and jquery plugin event we use the class TIWCGFunc for simple javascript events and TIWCGJSonFunc, a descendant of the previous, for jqplugin events

These are for properties of events class, explained:

- property Ajax: Boolean {default false}:

If the event is an Ajax event or a Full Submit Event. Ajax=true is comparable to events like OnAsyncClick and all IW natives that start with OnAsync.
We don't have one event for Async events, and other for full-submit events, because since they can't be used simultaneously, makes no sense to have two events, it's easy to change a property than move the code to the other event.

- property AjaxAppend: Boolean {default true}:

This prop is rarely used, it should be always true. If false, the event its only sent if the Browser isnt processing any other events.

- property AjaxQueued: Boolean {default False}:

if the event is to be queued, with a short timeout.

AjaxQueued and AjaxAppend are used in IW js function executeAjaxEvent and correspond to the arguments

SendDirect and Append, SendDirect = not AjaxQueued

- property BrowserParams: IWCGBrowserParams:

This is a collection of items that define the data to be sent from the browser to the server on each event. Each BrowserParam Item has the following properties:

- ServerName: The name that will be used in the OnEvent event param AParams: TStrings
- BrowserScript: The script expression that will be sent to the server. This could be any javascript expression, like for instance

$(“#IWEDIT1”).val()


or

document.getElementById("IWEDIT1").text()

there is a special tag that can be included in BrowserScript (and in Script property, explained bellow).


<#IWEdit1#>


will replace the name 'IWEdit1' by it's HTMLName ('IWEDIT1' in this case, but if contained in a frame will be different).

so


$(<#IWEdit1#>).val();


it's replaced by


$(“#IWEDIT1”).val()


internally

- SendJSon: If true the data is sent to the server using json format. This is useful if we want to serialize javascript objects. To deserialize, we can use ISuperObject in unit IWCGJSSuperObject. Example:
var o: ISuperObject;
o:= SO(SomeJSonValue); // being SomeJSonValue = ‘{string1:”somestring”, someint: 123, somefloat: 1.23, somebool: false; someobj:{s:”str”,i:123,f:1.23,b:true}}’;
o.S[‘somestring’] = ‘string’
o.I[‘someint’] = 123;
o.D[‘somefloat’] = 1.23
o.B[‘somebool’] = False
o.O[‘someobj’].S[‘s’] = ‘str’;


- property Condition: string:

This is an optional property to define a javascript expression that will be evaluated in browser to determine if the event is executed.

For instance, if we set Button.JQButtonOptions.OnClick.Condition:= 'confirm("Are you sure ?")';

first execute the javascript expression window.confirm("Are you sure ?")

and only if this evaluates to true the event will get called.

- property Script: string:

If we don’t need to call an event to server, we can execute a local script. At design time, there is a javascript editor with intellisense, to ease the process of write javascript.

- property OnEvent: TIWCGEvent:

This is the delpih event handler itself, the mosted used property, to actually write the server code.

- property Arguments: string:

This is a read-only property, but a very important property, that tell us what are the arguments of the javascript event counterpart that made the call in browser.

For instance

the jqgrid plugin, has the event onSelectRow with the arguments 'rowid' and 'status'.

if Delphi's TIWCGJQGrid.OnSelectRow.OnEvent is assigned, the control will generate the following javascript event:

onSelectRow: function(rowid,status) {
// ...
executeAjaxEvent(....);
}


The property TIWCGJQGrid.OnSelectRow.Arguments is 'rowid,status'.

Arguments, like 'rowid' and 'status' can be used in BrowserParams[].BrowseScript property, as the valid javascript it is within the js event.

- property SendAllArguments: Boolean {default False}:

If this property is set to True, the control will force browser to send all the arguments of javasript event. In this cases always set properties ServerName and BrowserScript to the argument names. BrowserScript = 'rowid'; ServerName = 'rowid';


CgDevTools
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

Return to Documentation / Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.