I. Overview
1.1 Requirement
In making a report, button widget is often used to handle values. The current default logic for getting values from the widget is that type a value into the widget, then click on any blank space or execute some other actions to make the widget lose focus. How to get the value from the widget immediately after it is typed?
The effect is demonstrated as below:
If you type a value in the cell in Column B and click the button [Direct addition] (which is enabled by default logic), it fails to get the value. But if you click the button [Optimized] (which is optimized using JavaScript), it directly gets the value.
1.2 Solution
Get the value from the widget by forced cursor jumping via JavaScript.
You will learn |
---|
|
II. Sample
2.1 Design of a report
1)Add a Text widget into A3 and B3 respectively.
2)Add a Button widget into D3 and E3 respectively.
3)Insert a formula into C3, i.e. the sum of the values in A3 and B3.
2.2 Add a JS event to the button widget with default logic
Name the Button widget in D3「Direct addition」and add a Click event:
Input the following JavaScript codes:
var B3 = contentPane.curLGP.getCellValue("B3");
var A3 = contentPane.curLGP.getCellValue("A3");
alert("The value of A:"+A3);
alert("The value of B:"+B3);
2.3 Add a JS event to the optimized button widget
Name the Button widget in E3「Optimized」and add a Click event:
Input the following JavaScript codes:
contentPane.curLGP.selectTDCell("A2"); // If a new value is just typed into the Text widget, this statement will make the widget lose focus, and input the following statements to get a new widget value.
var B3 = contentPane.curLGP.getCellValue("B3");
var A3 = contentPane.curLGP.getCellValue("A3");
alert("The value of A:"+A3);
alert("The value of B:"+B3);
2.4 Preview
Save the template and click [Data Entry Preview]. The effect is shown below: