在 Xpages 中使用占位符属性和密码类型 [英] Use placeholder attribute and password type in Xpages

查看:25
本文介绍了在 Xpages 中使用占位符属性和密码类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编辑框,我想使用占位符 AND password='true'.更改 password='true' 会导致占位符不起作用,密码类型确实起作用.

I have an Edit Box that I want to use a placeholder AND password='true'. Changing password='true' causes the placeholder to not work, the password type does work.

我这样设置占位符:<xp:attr name="placeholder" value="Enter Password">/xp:attr>

您不能设置 type=password 或者您收到 XSP 错误,提示您改用 password=true.

You cannot set type=password or you get an XSP error telling you to use password=true instead.

顺便说一句:我使用的是占位符而不是标签,其风格与 Slobodan Lohja 的流行博客文章相同:http://xpagesbeast.com/uxdesign/customizing-the-html-log-in-form-with-bootstrap/(在他的例子中,他使用 passthruhtml,所以他不必处理这个问题.)

BTW: I am using the placeholder instead of labels in the same style as Slobodan Lohja's popular blog post: http://xpagesbeast.com/uxdesign/customizing-the-html-log-in-form-with-bootstrap/ (In his case, he uses passthru html so he doesn't have to deal with this issue.)

推荐答案

这有点小技巧,但我发现它是一种有用的模式,可以克服默认渲染器拒绝允许我们指定 HTML5 的问题输入组件的类型.

This is a bit of a hack, but I've found it to be a useful pattern for overcoming the refusal of the default renderers to allow us to specify HTML5 types for input components.

设置一个 styleClass,使其明显是特定类型的输入(即 passwordInput).

Set a styleClass that makes it obvious it's a specific type of input (i.e. passwordInput).

向页面添加scriptBlock:

<xp:scriptBlock>
    <xp:this.value><![CDATA[XSP.addOnLoad(function(){
    dojo.query(".passwordInput").forEach(function(eachInput){
        dojo.attr(eachInput, "type", "password");
    });
});]]></xp:this.value>
</xp:scriptBlock>

这将导致所有输入类passwordInput成为密码字段.您可以对任何属性操作使用相同的模式,但我最常使用它来分配 HTML5 输入类型 到标准 inputText 组件.

This will cause all inputs with a class of passwordInput to become password fields. You can use this same pattern for any attribute manipulation, but I most frequently use it to assign HTML5 input types to standard inputText components.

警告:如果您的页面上有部分刷新事件导致这些输入被重新加载,请确保包含 scriptBlock inside相同的刷新目标.否则,您的纯文本字段将在初始页面加载时成为密码字段,但在针对该字段或其容器的任何事件之后将恢复为纯文本字段;但是,如果 scriptBlock 在刷新目标内,则在呈现输入时,脚本将再次执行,再次使其成为密码字段.

Caveat: If you have partial refresh events on your page that cause these inputs to be reloaded, make sure to include the scriptBlock inside the same refresh target. Otherwise, your plain text field will become a password field on initial page load, but will revert to being a plain text field after any events that target the field or a container thereof; if the scriptBlock is inside the refresh target, however, when the input is rendered, the script will execute again, once again making it a password field.

这篇关于在 Xpages 中使用占位符属性和密码类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆