Obtaining All Values Selected in the Extended Widgets by JS

  • Last update:June 30, 2025
  • Overview

    Problem

    During data entry report creation, when the data entry widget is extendable for display, you need to obtain all values of the extended data entry widgets. For example, all values of the extended radio button group widgets are obtained, as shown in the following figure.

    动图1 - Copy - Copy.gif

    Implementation Method

    With the widget APIs, you can obtain an array of the widget objects according to the widget name, and iterate through and obtain all values selected in the widgets. For details about the API description, see Exclusive API for Data Entry Preview and General API for Widgets.

    Example

    Extendable Widget Preparation

    Radio Button Group Widget

    1. Create a template, add a radio button group widget to cell A1, set Widget Name to p1, as shown in the following figure.

    iconNote:
    The widget name p1 will be used together with the JS that will be added later. If you modify the widget name, modify the corresponding code in the JS accordingly.

    1.png

    2. Select cell A1, and set Expansion Direction to Vertical under Cell Attribute > Expansion > Basic, as shown in the following figure.

    2.png

    3. Select the radio button group widget in cell A1, and add a data dictionary for the widget, as shown in the following figure.

    3.png

    Inserting Row Button

    Add a button widget to cell B1, set Button Type to Insert Row, and set Specified Cell to A1, as shown in the following figure.

    4.png

    Obtaining the Values of the Extendable Widget

    1. Add a button widget to cell A3, set Button Type to Common, and set Button Name to Obtain All Values Selected in the Extended Widgets, as shown in the following figure.

    5.png

    2. Add a Click event for the button widget in cell A3, as shown in the following figure.

    6.png

    The JavaScript code is as follows.

    var temp = "";
    var arr = _g().getWidgetsByName("p1");
    //Obtain the array of the widget objects of the extendable radio button group p1.
    if (arr[0] != undefined) {
    for (var i = 0; i < arr.length; i++) {
    temp = temp + arr[i].getValue() + ' '; //If the array returned by the widgets contains more than one character, iterate through the characters and concatenate them.
    }
    } else {
    temp = arr.getValue(); //If the array returned by the widgets contains only one character, directly obtain the widget value.
    }
    alert(temp);

    Effect Preview

    PC

    Save the template and click Data Entry Preview. The following figure shows the preview effect on the PC.

    动图1 - Copy.gif

    Mobile Terminal

    The following figure shows the preview effect on the DataAnalyst app and the HTML5 terminal.

    动图2.gif

    Template Download

    For details, you can download the template Obtaining All Values Selected in the Extended Widgets by JS.cpt.

    Attachment List


    Theme: Data Entry
    • 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