跳到主要内容

SetFormat

设置当前文本字段的格式。

语法

expression.SetFormat(format);

expression - 表示 ApiTextForm 类的变量。

参数

名称必需/可选数据类型默认值描述
format必需TextFormFormat要设置的格式。

返回值

boolean

示例

为文档中的文本字段分配输入格式。

// How do I restrict a text field to accept only a certain type of input in a document?

// Enforce a structured input pattern on a text field to guide user entries in a document.

let doc = Api.GetDocument();
let textForm = Api.CreateTextForm({ key: "Phone", placeholder: "Enter digits" });
textForm.SetFormat({ type: "digit" });
let paragraph = doc.GetElement(0);
paragraph.AddText("Text form with digit format: ");
paragraph.Push(textForm);