Use placeholder attribute and password type in Xpages

北慕城南 提交于 2020-01-03 01:58:13

问题


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.

I set the placeholder like this: <xp:attr name="placeholder" value="Enter Password">/xp:attr>

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

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.)


回答1:


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.

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

Add a scriptBlock to the page:

<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>

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.

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.



来源:https://stackoverflow.com/questions/19146938/use-placeholder-attribute-and-password-type-in-xpages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!