This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Nov 12, 2013, 7:31 PM
13 Posts

server side field validation

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 9.0.1
  • Role:
  • Tags:
  • Replies: 0

I have 3 fields on my xpage.  Required fields are (field1 AND field2) OR field3.  The problem I am having is with the error message on field2.  The form will submit when field1 and field3 are filled in and field2 is blank, so in this instance, it should display an error message stating to fill in field2.  Or, the error message displays when field1 and field2 are blank and field3 contains a value.  All fields also have a "ValidateExpression" where I look up the code in the database to see if it's a valid code. Here is my source code:

<?xml version="1.0" encoding="UTF-8"?><xp:view xmlns:xp="http://www.ibm.com/xsp/core">

<xp:this.resources>

<xp:styleSheet href="/LegEthics.css"></xp:styleSheet>

</xp:this.resources>

<xp:this.data>

<xp:dominoDocument var="document1" formName="test"></xp:dominoDocument>

</xp:this.data>

<xp:panel>

<xp:inputText value="#{document1.EventCode1}" id="eventCode1"

disableClientSideValidation="true" styleClass="Fields">

<xp:this.validators>

<xp:validateExpression message="Invalid event code.">

<xp:this.expression><![CDATA[#{javascript:var eventcode = getComponent("eventCode1").getSubmittedValue();

var dbName = new Array("","");

if (eventcode != null) {

var validcode = @DbLookup(dbName,"EventCodesFirstHour", eventcode, 1);

if (validcode == null)

{ return false }

else

{ return true}

}

}]]></xp:this.expression>

</xp:validateExpression>

<xp:validateRequired

message="Must have value if harassment training is blank.">

</xp:validateRequired>

</xp:this.validators>

<xp:this.required><![CDATA[#{javascript:!(getComponent("eventCode2").getSubmittedValue() == "" && getComponent("eventCode3").getSubmittedValue() != "") && !(getComponent("eventCode1").getSubmittedValue() != "" && getComponent("eventCode2").getSubmittedValue() != "")}]]></xp:this.required>

</xp:inputText>

<xp:message id="message2" styleClass="ErrorMessage"

for="eventCode1" style="font-weight:bold">

</xp:message>

<xp:br></xp:br>

<xp:inputText value="#{document1.EventCode2}" id="eventCode2"

disableClientSideValidation="true" styleClass="Fields">

<xp:this.validators>

<xp:validateExpression message="Invalid event code.">

<xp:this.expression><![CDATA[#{javascript:var eventcode = getComponent("eventCode2").getSubmittedValue();

var dbName = new Array("","");

if (eventcode != null) {

var validcode = @DbLookup(dbName,"EventCodesSecondHour", eventcode, 1);

if (validcode == null)

{ return false }

else

{ return true}

}}]]></xp:this.expression>

</xp:validateExpression>

<xp:validateRequired

message="Must have value if harassment training is blank.">

</xp:validateRequired>

</xp:this.validators>

<xp:this.required><![CDATA[#{javascript:!(getComponent("eventCode1").getSubmittedValue() == "" && getComponent("eventCode3").getSubmittedValue() != "") && !(getComponent("eventCode1").getSubmittedValue() != "" && getComponent("eventCode2").getSubmittedValue() != "")}]]></xp:this.required>

</xp:inputText>

<xp:message id="message3" for="eventCode2"

styleClass="ErrorMessage" style="font-weight:bold">

</xp:message>

<xp:br></xp:br>

<xp:inputText value="#{document1.EventCodeSexHar}"

id="eventCode3" styleClass="Fields"

disableClientSideValidation="true">

<xp:this.validators>

<xp:validateExpression message="Invalid event code.">

<xp:this.expression><![CDATA[#{javascript:var eventcode = getComponent("eventCode3").getSubmittedValue();

var dbName = new Array("","");

if (eventcode != null) {

var validcode = @DbLookup(dbName,"EventCodesSexHar", eventcode, 1);

if (validcode == null)

{ return false }

else

{ return true}

}}]]></xp:this.expression>

</xp:validateExpression>

</xp:this.validators>

</xp:inputText>

<xp:message id="message1" for="eventCode3"

styleClass="ErrorMessage">

</xp:message>

<xp:br></xp:br>

<xp:button value="Submit" id="button1">

<xp:eventHandler event="onclick" submit="true"

refreshMode="complete">

<xp:this.action>

<xp:actionGroup>

<xp:saveDocument></xp:saveDocument>

<xp:openPage name="/MessagePage.xsp"></xp:openPage>

</xp:actionGroup>

</xp:this.action>

</xp:eventHandler>

</xp:button>

</xp:panel>

</xp:view>


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal