How to validate Combo Boxes outside of a form

How to validate Combo Boxes outside of a form

  
Following the tutorial on http://www.outsystems.com/learn/training/13/1707/690/server-side-validation-of-inputs/#VideoTitle, we can validate input server side, using the form "valid" property. However, my controls are not inside a form, so I don't find the way to validate them. Client validation doesn't work either. It appears that (just maybe), because Outsystems automatically asign a 0 value to the variable that holds the value of Combo Boxes, they doesn't respond with "Required" when no item is selected in client validation.

The problem: I don't find a simple way to validate that a selection of these combo boxes are required. If the user select nothing, ajax submit runs with 0 values for the combo boxes.

What should I do in this case?? Thank you!!
Hi Samuel,

I'm not sure I get what you're doing. Am I to understand that you want to check whether the user selected a value from a combo box? What is the combo box default value? Etc.
Yes sir. I just want to check, whether the user selected a value from a combo box. The selection in these combo boxes should be required. Client validation doesn't seems to work, and server validation as shown in the tutorial (http://www.outsystems.com/learn/training/13/1707/690/server-side-validation-of-inputs/#VideoTitle) doesn't apply here because I can't use the "valid" property of the form, because my combo boxes are not inside a form.

There's a way to make client validation to work with combo boxes?

Thank you


Kilian Hekhuis wrote:
Hi Samuel,

I'm not sure I get what you're doing. Am I to understand that you want to check whether the user selected a value from a combo box? What is the combo box default value? Etc.
 
 
Hi Samuel,

First, if you want to ensure the user sets a value, the default for the combo box needs to be a value that's not valid. The easiest way for this is to have a single Special List entry with an Option of "-" or "(please select a value)" or the like (anything that indicates to the user it still needs to select a value). Also, make sure that your combo box's Variable is set to its null value (i.e. NullIdentifier() for an identifier, 0 for an integer etc.). This will ensure the Platform shows your Special List entry.

If you want client-side validation, you need to set the Mandatory property of the combo box to True, and the Button's Validation to Client & Server. If you press the button and the default value is still selected, you get a "Required field" message next to the combo box. Note that in this case, the Action of the Button is not executed.

If you want server-side validation, you need to check the value of the Combo Box's Variable. If it's the null value (NullIdentifier() for an identifier, etc.), you know that the user did not select a valid value, and you can raise an error (with a Feedback Message, or by putting a message on the screen, or by making the combo box's border red, or whatever you fancy).

I hope it's a bit clearer for you now?
Thank you Mr. Hekhuis for your fast reply.

Let's see what I have:

1. I have a special list entry already. It first and only option reads "- Products -" and a value of -1 is assigned to that option.

2. The combo box variable, is a variable of type record (a record of the "Multipackage" table). The variable name is "Multipackage", and the property that holds the combo box variable is "Multipackage.ProductId". The variable seems set to be 0 value, because when the user select nothing and I debug the application, the variable hold a 0 value. (Again, the platform seems to set the 0 value by default)

3. The mandatory property of the combo box is set to "mandatory" already.

4. The button validation property is set to Client & Server already.

It still doesn't work :/

What I am missing here?? Thank you!!


Kilian Hekhuis wrote:
Hi Samuel,

First, if you want to ensure the user sets a value, the default for the combo box needs to be a value that's not valid. The easiest way for this is to have a single Special List entry with an Option of "-" or "(please select a value)" or the like (anything that indicates to the user it still needs to select a value). Also, make sure that your combo box's Variable is set to its null value (i.e. NullIdentifier() for an identifier, 0 for an integer etc.). This will ensure the Platform shows your Special List entry.

If you want client-side validation, you need to set the Mandatory property of the combo box to True, and the Button's Validation to Client & Server. If you press the button and the default value is still selected, you get a "Required field" message next to the combo box. Note that in this case, the Action of the Button is not executed.

If you want server-side validation, you need to check the value of the Combo Box's Variable. If it's the null value (NullIdentifier() for an identifier, etc.), you know that the user did not select a valid value, and you can raise an error (with a Feedback Message, or by putting a message on the screen, or by making the combo box's border red, or whatever you fancy).

I hope it's a bit clearer for you now?
 
 
Hi Samuel,

No fast reply this time, weekend happend :). As for your last post, I'm not sure I understand what you are doing. One typically specifies a Variable of type Identifier, not a whole record. I actually tried to use a structure as Variable, but the platform gives me a compiler error in that case. Can you share an OML that shows what you've been trying?
Ok let's clarify...

I have a variable of record type of a table as you can see in this image:



Then, my combo boxes variables, are fields of that record type variable, as you can see in one of my combo boxes properties right here:



As for my oml, I attached it to this message, although I don't know if it will be of much help, considering that it will give you a bunch of errors because it depends of a data extension that is connected to our database.

Again, thank you so much for you help! Any thoughts?
Solution
Ah, your variable is not the MultpackageDetailsRecord, but one of its attributes. I was already wondering...

Ok, that's a pretty complex screen. It may be that the Platform somehow gets confused as to what inputs need validation triggered by what link or button. As I can't debug it, as you rightly pointed out already, I can't work out why the client validation doesn't work*.

However, if you need server validation, then it's pretty simple: if the variable is 0, then there's nothing selected, and you can take the appropriate action (e.g. show a message).

*What you could do is copy and strip the screen, and see if it still doesn't work in a very simple case, that is a screen with a single button with Client/Server validation.
Solution
Yeah, maybe I should just do a manual, server side validation, checking if the variable is 0. I was just wondering if I could make the client side validation to work.

Again Mr. Hekuis, thank you so much for your help
You're most welcome :).