JS ウィジェット書き込み値を即時検証

  • 作成者:ayuan0625
  • 編集回数:13次
  • 最終更新:FRInternational 于 2021-06-01
  • I. Overview

    1. Application scenario

    It is hoped that after entering the value in the data entry widget, the verification will be carried out in a timely manner. If there is a problem, a prompt will pop up and the input value will be cleared. The example shown in the figure is that the input string must conform to the format set by the regular expression. If the format is not satisfied, a warning reminder will pop up, as shown in the figure below.

    In specific applications, you can formulate corresponding verification rules according to your needs.

    1.gif


    2. Realization idea

    In the edit end event of the widget, use the test method of JS to determine whether the value of the widget matches the regular expression. If it does not match, clear the input value.

    II. Example

    1. Design template

    Enter Number: in cell A1, and add a Text Field widget in cell B1, as shown below:

    2.png


    2. Add edit end event

    Select the text field widget in cell B1 and add an edit end event to the widget, as shown in the following figure:

    3.png

    The JavaScript code is as follows:

    var ch = this.getValue();
    var patrn = /\s*[0-9]{4,9}\s*$/;
    //Use regular expressions to define rules: The requirement must be a number and no less than four digits
    if (!patrn.test(ch)) {
    FR.Msg.alert("Tip", "The format is wrong, it must be a number and no less than four digits, the correct format is such as: 12345");
    this.setValue("");
    }

    2.3 Preview effect

    Save and click Data Entry Preview, if the content entered in the text box does not meet the rules, a warning will pop up, as shown in I.1.

    Note: Mobile terminal is not supported.

    III. Download template

    Click to download:

    JS_timely_verification.cpt


    Attachment List


    Theme: FineReport データ書き込み
    既に最初
    既に最後
    • Helpful
    • Not helpful
    • Only read