我在网上找到一个很棒的小Xsnippet来在SSJS脚本库中进行验证。
它运作良好,但有一件事我想改变,我就是不能。我想将显示错误控制放在正在验证的字段的右侧,并在那里显示错误消息。目前它出现在lotusFormRequired表单的标题和页面的lotusFormError部分。
在下面的图片中,我不希望错误出现在两个Xed out区域中,而我确实希望它出现在红色框的位置。
以下是SSJS的代码
var validateForm = function(){
var valid = true;
var control;
var val;
//Location Number is Required
control = getComponent("LocNum");
val = control.getValue();
if (isEmpty(val)){
valid = false;
postValidationError(control,"Location Number Is Required");
}
return valid;
}
function postValidationError(control, msg) {
if ((typeof msg) != "string")
return;
var msgObj = new javax.faces.application.FacesMessage(javax.faces.application.FacesMessage.SEVERITY_ERROR, msg, msg);
facesContext.addMessage(control.getClientId(facesContext), msgObj);
control.setValid(false);
}
function isEmpty(o){
return (o == null || @Trim($A(o)[0]) == "" ) ? true : false;
}
function $A( object ){
try {
if( typeof object === 'undefined' || object === null ){ return []; }
if( typeof object === 'string' ){ return [ object ]; }
if( typeof object.toArray !== 'undefined' ){return object.toArray();}
if( object.constructor === Array ){ return object; }
return [ object ];
} catch( e ) { Debug.exceptionToPage( e ); }
}
以下是表单行的代码:
<xe:formRow labelPosition="none" id="frLocationNumber">
<xp:table style="width:99%" border="0" cellpadding="0"
role="presentation" cellspacing="0" id="tblLocation">
<xp:tr>
<xp:td style="width:10%;min-width:10%;">
<xp:label id="lblDocumentType"
value="Location Number" for="fieldDocType"
style="white-space:nowrap;">
</xp:label>
</xp:td>
<xp:td>
<xp:inputText id="LocNum"
value="#{document1.LocNum}" style="width:300.00px"
disableClientSideValidation="true">
<xp:this.validators>
<xp:customValidator
validate="#{javascript:return false;}">
<xp:this.message><![CDATA[#{javascript:"Incorrect"}]]></xp:this.message>
</xp:customValidator>
</xp:this.validators></xp:inputText>
<xp:message id="LocNumErrMsg" for="LocNum">
</xp:message></xp:td>
</xp:tr>
</xp:table>
</xe:formRow>
以下是我添加到页面中的CSS,用于抑制我不想要的错误。
/* This will suppress errors at the top of forms */
.lotusFormErrorSummary {
display: none;
}
.lotusFormError {
display: none;
}
好的,我说得太早了。在浏览器中工作,但在客户端没有。
我找到了明确的答案。
表单表中有一个属性来禁用ErrorSummary。我把它设置为&#34; True&#34;我得到了我想要的行为。
答案 0 :(得分:1)
我找到了明确的答案。
表单表中有一个属性来禁用ErrorSummary。我将其设置为“True”,我得到了我想要的行为。