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 7, 2013, 6:30 PM
13 Posts

field validation on 3 fields

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

I have 3 fields on my xpage.  I need to do field validation where if field 1 and field 2 are blank, field 3 must have a value OR if field 3 is blank, field 1 AND field 2 must have values.  I put in a validate expression of:

<xp:validateExpression

message="Invalid event code.">

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

var eventcode2 = getComponent("eventCode2").getSubmittedValue();

var eventcode3 = getComponent("eventCode3").getSubmittedValue();

 

if (eventcode1 == null && eventcode2 == null) {

if (eventcode3 == null)

{ return false }

}

return true

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

</xp:validateExpression>

 

 

 

 

However, this statement is not working.  I never see the error message.  Any ideas?

Nov 7, 2013, 9:06 PM
366 Posts
What happens if...

you change the getSubmittedValue method to just getValue? method

Nov 7, 2013, 9:43 PM
13 Posts
got it to work

Actually, I got it to work by another method.  I selected the "required field" under the Validation tab under the field properties, then I selected the "compute value" where I put the code to check whether the field values for all 3 fields are blank.

Nov 7, 2013, 10:56 PM
453 Posts
Use the dataSource and getValue

While the getComponent().getValue() should work. I have run some speed tests and the getComponent is really inefficient. document1.getValue("yourField") would be way quicker. I know it may not be a big thing but I was using getComponent on a fairly complex XPage and converted them to use the dataSource and the result was pretty impressive. With fast computers and fast networks it is easy to get sloppy.

The first computer I used was a Univac in it's own Air conditioned room with 8K of core memory. Extra clock cycles was a big thing, should still be because they can sure add up.

Anyway, I think that use the getValue (as Paul has aleready suggested) and your code should work, use the datasource and it should work better.


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