I. Overview
1.1 Problem
In our reporting process, when the text length exceeds some specific value (for example: mobile phone number), we can appropriately remind the applicant.
In the actual data entry process, the code length may need to be fixed in a standard format, and the accuracy of the input data can be reminded and prompted in real time during the input process, and the input text can be monitored in time.
1.2 Solution
Add after editing event on the text widget to monitor the text length in real time. After entry, if the length is greater than the set length, it will not be entered and a pop-up reminder will appear.
Note: The mobile device does not support this function
II. Example 1: Length is fixed
Insert a text widget in A1.
Right-click the cell where the text widget is located, select [Widget Settings]-[Event] to edit, add the [after editing event], as shown below.
Input JavaScript:
var data=this.getValue();
//get cell value
var len=data.length;
//get length
if(len>10)
{
contentPane.setCellValue("B2",null,data.substr(0,10));
//If the length of the cell value exceeds 10 digits, the first 10 digits will be intercepted
alert("maximum number of digits is 10");
}
III. Example 2: Custom length
For the length that needs to be customized, template parameters can be generated. For example, select [template]-[template parameters] and add the following parameter:
In the widget event editor, refer to the parameter maxlen as shown in the figure below.
Input JavaScript:
var data=this.getValue();
var len=data.length;
if(len>Number(maxlen))
{
contentPane.setCellValue("B2",null,data.substr(0,10));
alert("maximum number of digits:"+maxlen);
}
Save the template and click [Data Entry Preview]: