Skip to main content

Posts

Showing posts from June, 2012

Move all your code into script libraries

Here is a little tip and the reason behind it: If you have any code on an XPage, replace it with a single function call and move the code to a script library. Example: If you have code like this on your XPage <xp:this.querySaveDocument><![CDATA[#{javascript: var foo = "hi"; var bar="there"; return (foo==bar?True:False);}]]></xp:this.querySaveDocument> Replace it with this <xp:this.querySaveDocument><![CDATA[#{javascript: return foobarQuerySave();}]]></xp:this.querySaveDocument> And create and include a script library with this function foobarQuerySave() {    var foo = "hi";    var bar = "there";    return (foo==bar?True:False); } Even if there is no code there currently, if you think there may ever be a need for it you should add a stub function that just returns true and call it. Here's why:

Setting a field attribute through javascript

Quick little post here about something that came up on a project. If you need to set an attribute of a field that the inputText bean does not have the attribute for, such as the TYPE attribute prior to 8.5.3, you can do so using javascript. Follow the field with a little script block that looks like this: <xp:scriptBlock value="document.getElementById('#{id:StartDate}').setAttribute('type', 'date');"> </xp:scriptBlock>