This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.

Oct 11, 2015, 11:24 AM
25 Posts

combo box validation

  • Category: Other
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags: combo box validation
  • Replies: 4

I have a combobox and I am trying to validate it. The default value = " "

<xp:comboBox id="comboBox1"
                    <xp:selectItems id="selectItems1">
                        <xp:this.value><![CDATA[#{javascript:var arr = new Array(" ");    
var rgs = @DbColumn("", "RolesforDB", 1);
var list = arr.concat(rgs);
return list; }]]></xp:this.value>

                    <xp:eventHandler event="onfocus" submit="true"
                        refreshMode="norefresh" id="eventHandler3">
                    <xp:eventHandler event="onchange" submit="true"
                        refreshMode="partial" refreshId="comboBox2" id="eventHandler7">


I am trying to validate that has a value selected other than " ";

I have searched and I purchased courses, but I still don't understand how to validate a combobox.

I am building my first xpage site, and am desperate, as I am sure everyone is who comes here. Anyway, any help would be greatly appreciated.


Thank you so much in advance.




Betsy Thiede




Oct 11, 2015, 3:38 PM
453 Posts
Well first...

I do most of my validation in the QuerySave event. You have much more control and I like having all the validation in one spot so I don't have to search through field by field. In your example not sure why you have the onFocus event. You could put an onBlur event and check  if (domonoDoc.getItemValue(ReaderGroup)[0] == "") or look at the All Properties /Data/Validator to check if ReaderGroup has a value. The problem I have with that is that it will fire on every refresh and you will need to be checking if it is a valid Validation. 

Others might have a better solution but I struggled with the Validators for a lot of time before I just put most all of them in the querySave. Obviously there are some validators that need to be done at the 'field' level, but I would suggest that this might be a case for the QuerySave event. I used to do that in Native Notes As well.

Oct 11, 2015, 5:51 PM
25 Posts
Bill.. that sounds so much better

I took out the focus code. Not sure why it was there.

<xp:tr themeId="HtmlTr.form.body">
            <xp:td themeId="HtmlTd.form.body.label">
                <xp:label value="Reader Group:" id="label1" themeId="Text.table.label">
            <xp:td themeId="HtmlTd.form.body">
                <xp:comboBox id="comboBox1" value="#{dominoDoc.ReaderGroups}">
                    <xp:selectItems id="selectItems1">
                        <xp:this.value><![CDATA[#{javascript:var arr = new Array(" ");    
                            var rgs = @DbColumn("", "RolesforDB", 1);
                            var list = arr.concat(rgs);
                            return list; }]]>
                    <xp:eventHandler event="onchange" submit="true"
                <xp:message id="messageReaderGroups" for="comboBox1"
                    showDetail="false" showSummary="true">

As far as the querysave,

I'm not sure what I would put in there.

I am modifying a custom control, called mainTopic.. I see it has a querySaveDocument event..

Since I am modifying a database I created from the standard discussion document, it has stuff that I have no idea what it means, especially since this is my first xpage application.

// store user CGI variables
var cgi = new CGIVariables();
dominoDoc.replaceItemValue("Remote_User", cgi.get("REMOTE_USER"));
dominoDoc.replaceItemValue("Remote_Addr", cgi.get("REMOTE_ADDR"));
cgi = null;

That is what is in the querySaveDocument now..

so, would I just do

if(domonoDoc.getItemValue(ReaderGroups)[0] == " ")


//not sure what to do if it does = " ".. meaning, how do I stop it from saving or submitting?

return false;


Thank you so much for your help


Oct 12, 2015, 8:34 AM
589 Posts


do you have this working now?  Is this still an issue?

Oct 12, 2015, 11:10 AM
453 Posts
The return = false...

Causes the QuerySave to fail and return to the main document. I put an error message in a viewScope.vsReturnError = "You must select a value"; or what ever. then have a Computed text field on you form that displays if  viewScope.vsReturnError != "". I believe the return from the QuerySave does a full refresh so there should be no issues with the display needing a refresh.

In my querysave code I do all my required field checking and return vsReturnError as an array of message strings. I can then customize the return message for each evaluation. I find this process much easier to handle the situation where if fieldA has a value then FieldB and FieldC are required.

This is just the way that I have done this. but as is generally the case there are many different ways to do the same thing. I have a SSJS script library jsQuerySave that I put all of the querysave code in. In it I have a 'method' doQuerySave that returns true or false. I pass function doQuerySave(thisDoc:NotesXspDocument, action:String) so that based on the action type I can modify the list of required field. In my case I have a Save action but I also have a Submit For Approval action. A simple Save action does not have as extensive a set of required fields as does a Submit for Approval. Also, in my case the doQuerySave contains the querySave code for the whole Application which can contain many different document types, so I check the Form Name and based on that perform different actions on the document. Also, in my case the doQuerySave does a lot more than just verify the required fields. 

I have written it in SSJS because when I started it I had no java experience. If I was starting it today I would probably do it in Java, and I will in all likelihood rewrite it some day, but in any case I really like being able to open the jsquerySave library and have all my querySave event in one place, and much of the code applies to all querysave events so is only written once and reused. Find a Bug only need to fix it in one place.

As I said this is just the way I do it, others might do differently.

This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.