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



Mar 7, 2011, 7:03 PM
45 Posts
topic has been resolvedResolved

Computed Validation JavaScript

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: End user
  • Tags:
  • Replies: 5
Hi,
 
I am trying to compute the Validation message for string length, i.e. one message if it less than 10 characters and another message if it is greater than 75 characters. I have set the Max & Min parameters. But cannot get the 'too many characters' to display a different message, i.e .when greater than 75.
 
I am new to javascript so sorry if I have missed something obvious, but I have tried every combination I can possibly dream up this is just one sample.
 
Any help would be appreciated. 
 

var errmessage;

var text = @Length(getComponent("faultDescription").getValue());

if( text <= 10)

{errmessage = "Sorry the description is not meaningful";}

else

{errmessage = "Sorry you have used too many characters";}

return errmessage;

 
Mar 7, 2011, 7:17 PM
149 Posts
Re: Computed Validation JavaScript
try this
 
var text = @Length("testingtesting");
var errmessage;

if( text < 5){
    errmessage = "Less than 5";
}else if(text>30){
    errmessage = "more than 30";
}else{
    errmessage = "between 5 and 30";
}

return errmessage;
 
Mar 8, 2011, 1:46 PM
45 Posts
Re: Computed Validation JavaScript
Hi sorry I probably wasn't clear, the string needs to come from an Edit Box Control. The Validation is associated with its Validation Properties  Maximum and Minimum Values with computed error message and an associated Display Error Control
Mar 8, 2011, 3:44 PM
22 Posts
Re: getComponent('controlname').getValue() returns an array of length 0...
Try getValueAsString() instead:
 
var comment1:com.ibm.xsp.component.xp.XspInputText = getComponent("comment1");
var text = comment1.getValueAsString();
var textLen = @Length(text);
var errmessage = ( textLen <= 10)? 'Sorry the description is not meaningful' : 'Sorry you have used too many characters';
return errmessage;

Also make sure the property disableClientSideValidation is set to true.

Newbs
Mar 8, 2011, 4:25 PM
45 Posts
Re: getComponent('controlname').getValue() returns an array of length 0...
Fantastic, it works Henry.
 
I wondered whether I should be using all that  comment:com.ibm.xsp.component.xp.XspInputText   stuff and that it might be to do with arrays, but it would have taken me even longer than it has to come up with that.
  
 
Many thanks guys. 
Mar 8, 2011, 5:25 PM
22 Posts
Re: You do not have too, but it allows the helper processes to work...
I use the Control Declaration Snippets in the DDE to get the correct syntax for a control. Easier than remembering the all the containers...
 
Newbs

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