onDialogInitialize

IN THIS PAGE

Description

Fires the first time the UX Component is run.

The onDialogInitialize event is used in this guide to creating 'Variable Choices' in a UX Textbox control.

Request 

The Request object. Includes Request.Variables, which should be used instead of the older e.rv construct

Session 

The Session object. Should be used instead of the older e.session construct

Inside e: 

e.tmpl

Component definition

e.rtc

Runtime calculations - you can use this to store data to be passed to other server side events (Note: the 'rtc' object cannot be used to persist state information - i.e. you can't set a value in rtc and then read that value in a subsequent callback. To persist state info see e._state).

e.arguments

SQL::Arguments object with values for each of the arguments defined in this component. To read a value from arguments: e.arguments.find("argumentName").data

You can also set the value of an argument. For example: e.arguments[e.arguments.ArgumentNumber("country")].data = "portugal"

You can set the initial value of any field by setting the property (see comment at end for Javascript technique to use when setting values for a large number of controls) e.control.<fieldname> For example:

e.control.firstname = "Fred"
e.control.lastname = "Jones"

For multi-valued controls (such as checkbox, List control configured as multi-select, etc.) you can set the value to a cr-lf list of values or use the special array() syntax. Either of the following two methods will work

e.control.colors = "array(red,green)"
e.control.colors = comma_to_crlf("red,green")

To set the value of a field in a repeating section, you must use "_A5INSTANCE" and the instance number as a suffix on the fieldname. For example, the following code sets the value in the 2nd row of the repeating section.

e.control.firstname_A5INSTANCE2 = "Bob"

To specify any javascript that you want to execute set the e.javascript property. For example:

e.javascript = "alert('hello');"

You can set 'state' variables in this event. The value of any state variables will be available in all subsequent ajax callbacks. To set a state variable:

e._state.myvar1 = "value1"
e._state.myvar2 = "value2"

Using Javascript to Set Control Values and the Row Count in a Repeating Section -- Recommended For Maximum Efficiency (Advanced users)

When setting the value of a large number of controls, you will improve performance if you generate the Javascript directly, rather than setting properties in the e.control object (as described above) and then having Alpha Five generate the Javascript from this object. The following example shows Javascript code that sets the number of rows in a Repeating Section and sets the value of various control in the top section and Repeating Section of the Dialog:

Generate the Javascript to emit

dim js as c
js = <<%txt%
var rows = 7;
var setFocusToFirst = true;
var nullOutExistingData = true;
var repeatingSectionId = 'CONTAINER_1';
{dialog.object}._setRepeatingSectionRowCount(repeatingSectionId,rows,setFocusToFirst,nullOutExistingData);
var _d = {};
//Next command is optional. It is ONLY needed if the ._setRepeatingSectionRowCount() method
//has been called. The command copies default values into the _d object.
//Without this command, default values defined in the component will not be set.
//$u.o.assign(_d,DLG1_DlgObj.originalValues[0]);
_d['B'] = 'alpha'; //set the value of a control called 'B'
_d['E:2'] = 'beta'; //set the value of a control called 'E' in the 2nd Repeating Section row
_d['G:6'] = ['Red','Green']; //set the value of a checkbox called 'G' in the 6th Repeating Section row to 'Red' and 'Green'
{dialog.object}.prepare();
{dialog.object}.populate(_d);
{dialog.object}.refreshClientSideComputations();

%txt%

Now, emit the Javascript...

e.javascript = js

In the above example, if the ._setRepeating() method is called in the 'onDialogInitialize' event, you are responsible for setting values in ALL of the controls in the component. For example, if you have defined default values for some controls, and then set the values of other controls using the .populate() method, only the values set in the _d object will be set. (The default values will NOT be set). You can, however, put the default values into the _d object using this code:

$u.o.assign(_d,{dialog.object}.originalValues[0]);

You can use the Xbasic varToJSON() function to help generate the Javascript object passed to the .populate() method. For example:

dim j as p
j.firstname = "John"
j.lastname = "Smith"
j.quantity_a5instance1 = "2"
dim j.colorchoices_a5instance2[3] as c
j.colorchoices_a5instance2[1] = "Red"
j.colorchoices_a5instance2[2] = "Blue"
dim jsTxt as c
jsTxt = varToJSON(j)
js = "{dialog.object}.populate(" + jsTxt + "); {dialog.object}.prepare();"

To simulate session variables when running in Working Preview you can use this code:

if eval_valid("request.SERVER_PROTOCOL") then 
	if request.SERVER_PROTOCOL = "A5RES" then 
		'running in working preview
		session.var1 = "simulated value for var1"
	end if 
end if