REMINDER:
On December 1, 2018, this forum will be closed to new posts and responses. After that date, you will still be able to view and search the forum. New discussions should take place in the IBM Developer Answers forum.



May 4, 2011, 3: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, 3: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, 4: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, 7:01 AM
1 Posts
7 years later

...but thanks for this! 


REMINDER:
On December 1, 2018, this forum will be closed to new posts and responses. After that date, you will still be able to view and search the forum. New discussions should take place in the IBM Developer Answers forum.