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



Dec 4, 2013, 3:23 PM
10 Posts

Validate Rich Text Field in a XPage

  • Category: Other
  • Platform: Windows
  • Release: All
  • Role: Developer
  • Tags:
  • Replies: 3

Hello - I am trying to validate a rich text field on a XPage from a button.  Basically, I want make sure that the rich text field is not blank before processing the SSJS code in the button.  I was trying to use something like the code below but I noticed if I just put a space or a carriage return without any text, it still processes the document even though the rich text field is blank.  Any suggestions would be appreicated and thanks in advance for your help.

var fieldid = '#{javascript:getClientId("rtResolution")}';

 

if (null == fieldid) return true;

var field = dojo.byId(fieldid);

var value = field[field.selectedIndex].value;

if (value == '') {

alert("You must enter a resolution before proceeding.");

window.scrollTo(0,0);

field.focus();

return false;

}

return true;

Dec 4, 2013, 4:02 PM
366 Posts
If you copied the code...

your second if statement contains a type

value == "

versus

value ==""

You can also trim the returned value to strip spaces 

Dec 4, 2013, 5:02 PM
10 Posts
Replaced/Fixed Code

Hi Paul - Thanks for your response.  I replaced value = '' with value = "" and it still lets me process the document without a value in the field.  Is there something special I need to check in the rich text field for xpages?  I understand that the field is treated differently in Xpages than in notes.  I've been working with Xpages for a while but I am still new with rich text fields.

Dec 9, 2013, 3:51 PM
586 Posts
hmmm

I don't do much with rich text...  thank goodness...  :)

You might want to try changing your if statement...

instead of:

if (value == "") {

You may want to try:

if ( "".equals(value)) {

this really is necessary in Java - which is what really runs XPages.  I'm a little uncertain about it for SSJS...  but I believe it's the better way to go.

Basically in Java a literal string is an Object.  so the literal "Test" is an object the same as your variable "values" is an object.  And even if the text "Test" was inside the variable "values", the test if ("Test" == values) is comparing 2 different objects and those objects are not equal to each other.

But if you did :  if ("Test".equals(value)) 

then it knows to look not at the objects themselves but the strings inside them.

 

So you can say if ( "".equals(values) {

to mean if the contents of values is a blank or "" then it's true.

 

Sorry I rambled there but that's an important distinction in XPages String comparison.

 

Hope that helps

 

Dave


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