Compatibility check, switches, buttons, etc.?

I am using the ErrorMessage control on my form to validate things like Edit Fields. Works great. When data entry is required, a gray warning window appears.

Can anyone point me to an example of how I can do the same for radio buttons, combo boxes, etc.? Or even a regular button (let's say I have a button to add a document on a form).

I really don't care how the message is actually displayed. I would just like my validation to be consistent across all my components. In other words, I don't want any server side and some client side validation.

Are there any examples? I am using my own validation using the ext lib dialog which works well, but I was hoping something easier to implement.

+3


source to share


4 answers


I am using an extended version of this XSnippet when checking out . This allows you to manage all of your validation in a central SSJS library, and then display all errors in a Display Errors control.

In the central SSJS library, you can inspect your controls, including radio buttons, combo boxes, etc., and combine your checks (for example, check the value of one control when another control has a specific value).



Here's an example baesd for the mentioned XSnippet to check if a specific field (FieldA) has been filled when the radioField group is 1:

var radioVal = getComponent("radioField").value;
var control = getComponent("FieldA");
var val = control.getValue();
if (radioVal == "1" && isEmpty(val)){
  valid = false;
  postValidationError(control, "Please fill in ...");
}

      

+5


source


I hope that with the ErrorMessage control you mean the "Display Error" control. For a combo box, in all properties inside "data", you will find "validators". Here you can add your checks in the same way as for edit fields. For combined, I usually use validateExpression

. Then I use the Display Error control to display the errors.

<xp:comboBox id="comboBox1">
    <xp:this.validators>
        <xp:validateExpression message="Please select value in combo box.">
            <xp:this.expression><![CDATA[#{javascript:!getComponent("comboBox1").getSubmittedValue().equalsIgnoreCase("Select")}]]></xp:this.expression>
        </xp:validateExpression>
    </xp:this.validators>
    <xp:selectItem itemLabel="Select" itemValue="Select"></xp:selectItem>
    <xp:selectItem itemLabel="1" itemValue="1"></xp:selectItem>
    <xp:selectItem itemLabel="2" itemValue="2"></xp:selectItem>
    <xp:selectItem itemLabel="3" itemValue="3"></xp:selectItem>
</xp:comboBox>
<xp:message id="message1" for="comboBox1"></xp:message>

      

In the above example, if the user does not select any item in the combo box, an error message is displayed to the user. Please note that this is a server side validation. I haven't tried this for other controls, but it should work in a similar way.



Let me know if I understood your question correctly.

Update February 7, 2013: Take a look at the comment below by Michael Grevenstan for a better way.

+3


source


It was possible to test a group of radio buttons with @GetField and the group name.

In this example, the group name was BankLoss:

// BankLoss
var radio1 = @GetField("BankLoss")
if (radio1 == null || radio1 == ""){
    valid = false;
    errors.push("Please indicate if there was a potential bank loss.");
}

      

Worked for me ...

0


source


Even the simplest and simplest: if you have the "Select option" option and set the value to "" empty, you can use validateRequired and that's it. Example:

If the combobox values ​​are:

["-Select an option-|","Text1|Value1","Text2|Value2"] 

      

You can, as @Naveen said, go to all properties> data> validators> +> ValidateRequired> Set Post and you're done.

0


source







All Articles