JS Solves Component Value is not Refreshed on time

  • Last update:December 15, 2020
  • 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.gif

     

    1.2 Solution

    Get the value from the widget by forced cursor jumping via JavaScript.

    You will learn
    • Sample

      • Design of a report

      • Add a JS event to the button widget with default logic

      • Add a JS event to the optimized button widget

      • Preview

    • Download the template

    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:

    5.png 

    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:

    6.png 

    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:

    7.gif 

    III. Download the template

    0.cpt

     

    Refer to the original link: https://help.finereport.com/doc-view-1887.html

     


    Attachment List


    Theme: Data Entry
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy