JS Limit Checkbox (Parameter Panel) to Select the Number

  • Last update:December 01, 2020
  • I. Overview

    1.1 Problem description

    For some special query templates, if there are too many options for drop-down check boxes, the query results may be too large, and the page display effect may be not ideal, so it is sometimes necessary to limit the number of check box groups selected. For example, the number of selectable check boxes is limited to 5, and if there are more than 5 check boxes, extra check boxes cannot be selected. Let's introduce the production method below.

    For example: If apple juice, milk, tomato sauce, salt and sesame oil have been selected, when you want to check soy sauce, you can't select it and a prompt box will pop up showing [You can only select 5 at most!].

    1.PNG 

     

    1.2 Implementation ideas

    Get the value of the current widget through JavaScript, and then judge the number of selected check boxes and perform operations.

    You will learn

    • Examples

      • Operation steps

      • Preview

    • Completed template

    II. Examples

    2.1 Operation steps

    Add a click event to the check box group widget, as shown below:

    2.png 

    The code is as follows:

    var Num = 0;
    $.each(this.ck_el_array, function(i, item) {
        if(item.isSelected()) {
            Num++;
        }
        if(Num > 5) {
            FR.Msg.toast("At most choose 5 items");
            item.setSelected(false);
        }
    });

    Note: Currently, this method only supports selecting options in positive sequence. If you select in negative sequence, when there are more than 5 options, the first option will be unchecked while the current option will be checked.


    2.2. Preview

    Save the report and click Pagination Preview. The report effect is as shown below:

    3.gif 

    Note: Mobile terminal is not supported.

    Note: Save the template, click Pagination Preview, and only 5 check boxes can be selected at most, otherwise the above dialog box will pop up.

    III. Completed template

    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