JS Control whether the Parameter Widget is Displayed

  • Last update:  2020-12-04
  • I. Overview

    1.1 Requirement

    How to have some widgets displayed only when certain conditions are met? See the effect as shown below:

    Only when an option is picked in the previous drop-down box, the next drop-down box will be displayed:

    1.gif 


    1.2 Solution

    Set the widget/widgets to be displayed subsequently [Not Visible] or [Not Enabled], then add an After Editing event to the first widget, and finally use JavaScript to make the widget/widgets to be displayed subsequently [Visible] or [Enabled].

    You will learn
    • Sample
      • Initialize the widget to Not Visible
      • Add events to widgets
      • Preview
    • Download the template

    II. Sample

    2.1 Initialize the widget to Not Visible

    1) Select Project_name, click [Properties]-[Basic], and uncheck [Visible], as shown below:

    2) Set the Year widget Not Visible:

     

    3) Set the Label widgets Project_name and Year Not Visible.

    7.png 


    2.2 Add events to widgets

    1) Select Asset_category, add an After Editing event, and set Project_name Visible using JavaScript:

     

    Input the following JavaScript codes:

    var Project_name = this.options.form.getWidgetByName("Project_name");
    var thislen = this.getValue().length;
    if(thislen) { // If any option of Project_category is picked, set Project_name and the Label widget Visible
        Project_name.setVisible(true);
        this.options.form.getWidgetByName("label3").setVisible(true);
    } else { // If no option of Project_category is picked, set Project_name and the Label widget Not Visible
        Project_name.setVisible(false);
        this.options.form.getWidgetByName("label3").setVisible(false);
        alert("Please choose the Asset_category");
    }

    2) Add an After Editing event to Project_name as well:

    5.png 

    Input the following JavaScript codes:

    var Year = this.options.form.getWidgetByName("Year");
    var thislen = this.getValue().length;
    if(thislen) 
    {  //If any option of Project_name is picked, set Year and the Label widget Visible
        Year.setVisible(true);
        this.options.form.getWidgetByName("label5").setVisible(true);
    }
    else {  // If no option of Project_name is picked, set Year and the Label widget Not Visible
        Year.setVisible(false);
        this.options.form.getWidgetByName("label5").setVisible(false);
        alert("Please choose the Project_name");
    }

     

    2.3 Preview

    Save the template and click [Pagination Preview]. The preview effect on a PC is shown as below:

    6.gif 

    III. Download the template

    1.cpt

     

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

     


    Attachment List


    Theme: Parameter
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    10s後關閉

    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