XPages: Bootstrap Validator

旧城冷巷雨未停 提交于 2019-12-08 21:01:30

The jQuery Mask plugin uses AMD loader which conflicts with XPages. Therefore your jQuery Mask plugin does not load at all.

The fix is to remove from jquery.mask.min.js the part where AMD is used. So open jquery.mask.min.js and change from this:

// jQuery Mask Plugin v1.7.7
// github.com/igorescobar/jQuery-Mask-Plugin
(function(f){"function"===typeof define&&define.amd?define(["jquery"],f) ...

to this:

// jQuery Mask Plugin v1.7.7
// github.com/igorescobar/jQuery-Mask-Plugin
(function(f){"function"===typeof define&&false?define(["jquery"],f) ...

This ensures that AMD is not used to load the plugin.

Update: Make sure to use the x$ XSnippet in order for jQuery selectors to work with the colons in the XPages client side ids.

One suggestion, change the find line to use the id instead:

.find('*[id$="ipAddress"]').mask('099.099.099.099');

[Per's answer solves this secondary issue] -> However, I found that when adding the /jquery.mask.min.js file to my xpage resources, it causes no jquery on the page to execute, with no errors in the firebug console. I pulled the mask.min.js content from here. Not even the below code would work with the mask js file in the resources:

<xp:scriptBlock id="script1">
    <xp:this.value><![CDATA[
        XSP.addOnLoad( function() {
            $("*[id$='msg']").html("JQUERY Working");
        });]]>
    </xp:this.value>
</xp:scriptBlock>
<xp:div id="msg"></xp:div>

As soon as I removed the mask resource, the above works fine. I am using jquery 2.1.1. I would recommend you try something like this too, to check if the mask plugin is the root of the problem.

UPDATE: I created a jsfiddle that works: http://jsfiddle.net/m2325jhc/2/. I found that there were issues using the name to find the object, but it works using the id instead. Per's answer solved the issue of jquery breaking in my xpage app, with the mask plugin.

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