如何编写 HTL 查询以将表单输入从文本更改为电话

How to write HTL query to change the form input from text to tel

我有自定义表单组件。当它发现 html pattern="[+0-9()-]*" 从文本到电话时,我必须更改表单的输入类型。可以用HTL吗

您不能完全在 HTL 表达式中进行这些检查。您将需要一个 Use 对象来检查输入并显示它是否为电话号码:

<sly data-sly-use.myModel="...">
<input type="${myModel.isTelephone ? 'tel' : 'text'}"...

您还可以查看属性文档:https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#attribute 在这种情况下 data-sly-attribute.type="${myModel.type}" 在您的模型中您可以根据提交的值决定是要 tel 还是 text .如果你想在用户输入数据时改变它,那么你需要在 clientlib 中做,因为 HTL 是服务器端而不是客户端。希望对您有所帮助。