对电话号码字段启用格式设置
您可以对电话号码字段启用格式设置,以在使用电话号码作为条件对客户执行搜索时控制数据。
过程
- 创建格式化程序以实现电话号码的定制格式化,并将其添加到
extn/utils目录,其中extn映射到<runtime>/extensions/。 注册期间需要目录路径。 以下代码片段定义格式化程序:wsc/webpages/
此处,格式化程序方法用于扩展scDefine(["scbase/loader!dojo/_base/declare" , "scbase/loader!sc/plat/dojo/app/IFormatter" ], function(dDeclare, scIFormatter ){ var scPhoneNoFormatterType = dDeclare("extn.utils.PhoneNoFormatterType", [scIFormatter],{ format: function(type, input) { var val = this.removeNonDigitCharacters(input); if(val.length != 9 ) return val; return "(" + val.substring(0,2) + ")" + val.substring(2,4)+"-"+val.substring(4,9); }, deformat: function(type, input) { return this.removeNonDigitCharacters(input); }, removeNonDigitCharacters: function(input) { return input.replace(/[^0-9]/g,""); } }); return scPhoneNoFormatterType; });IFormatter接口。 - 针对应用程序初始化时装入的文件中的 "formatter type" 注册格式化程序。 例如,在
container.jsp或主页扩展中。 必须确保在屏幕中使用格式化程序之前完成注册。"formatter type" 是定制格式化程序的名称。 在此示例中,"phoneNoFormatter"是 "格式化程序类型"。 以下样本代码片段演示如何注册格式化程序。scDefine([ ... "scbase/loader!sc/plat/dojo/app/FormatterUtils", "scbase/loader!extn/utils/PhoneNoFormatterType"], function(.... ,scFormatterUtils, scPhoneNoFormatterType) {.. scFormatterUtils.registerFormatter("phoneNoFormatter", new scPhoneNoFormatterType(), 1);... }); - 使用扩展性工作台 ,在 " 属性 "面板的 " 其他 "选项卡中为文本框和数据标签添加格式化名称属性。 在此示例中,格式化程序名称为
phoneNoFormatter,这是在步骤 2 中注册的格式化程序类型。 - 构建和部署 WAR ,重新启动服务器以及清除浏览器高速缓存。