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



May 4, 2011, 7:28 AM
7 Posts

A simple validation that XPages is unable to handle?

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: xpages validation
  • Replies: 3
Hi,
 
I have a simple validation that I want to perform. Let's take for example one field, with the following simple validation requirement:
 
- the field is only required if a certain set of conditions is set
- if the user forgets to enter something in the field, a custom error message should be displayed in the <xp:messages> area
 
I think I have the following 3 options to perform this validation

1) Use the "required" property, which allows me to use a formula.
 
Pro: We can dynamically calculate if the field is required or not
Con: Generates a default error, which can't be changed
 
2) use a <xp:validateRequired> 
 
Pro: Can display a custom error message
Con: Is not dynamic (value is always required)
 
3) use a <xp:validateExpression>

Pro: Can display a custom error, and allows me to check dynamically if the field is required
Con: Does not fire when the field is empty

How am I supposed to handle such a simple validation in XPages? This is driving me nuts ...
 
 
May 4, 2011, 7:45 AM
261 Posts
Re: A simple validation that XPages is unable to handle?
Jeroen,
 
I've solved this issue using the disableValidators property of a field. It allows you to disable the validators attached to a field, based on a (runtime) condition.
 
Sample:

<xp:this.validators>
                                    <xp:validateRequired
                                        message="This field is only required if another condition is met.">
                                    </xp:validateRequired>
</xp:this.validators>
<xp:this.disableValidators><![CDATA[#{javascript://disable validators based on some condition
if ( currentDocument.getItemValueString("fieldIsRequired") == "1") {
 return false;
} else if (getComponent("fieldIsRequiredComponentId").getValue() == "1") {
 return false;
} else {
 return true;
};
}]]></xp:this.disableValidators>
May 4, 2011, 8:02 AM
7 Posts
Re: A simple validation that XPages is unable to handle?
Thanks, this seems like a useable work-around !
Nov 10, 2018, 12:01 PM
1 Posts
7 years later

...but thanks for this! 


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