A Legacy Notes Developer's journey into madness.

Invalid Validation Frustration Situation

Devin Olson  October 5 2012 04:36:07 AM
Last night just as I was shutting down my boss pointed out a problem in an application I'm working on.   It seems validation was failing on a certain field.  I did a quick test and was able to reproduce his results.  

The setup:
I have an XPage upon which is a MultiLine Edit Box control (xp:inputTextArea).   This is a required field for the particular document being presented in the XPage -users must enter content in order to save the document.  So I had set it as required by checking the "Required Field" checkbox and filling out the Required Field Error Message  (Validation tab of Properties for the Multiline Edit Box control in Designer).   The XML for the control was:

<xp:inputTextarea
id="subject1"
rows="5"
style="width:99%"
value="${javascript:'#{compositeData.requestDocument.subject}'}"
multipleSeparator="#{javascript:@NewLine()}"
required="true">
<xp:this.validators>
<xp:validateRequired
    message="Please explain the issue for which you need help." />
</xp:this.validators>


This was working fine for single and multiple lines, but if multiple lines were entered and one (or more) of them were BLANK lines, then the validation would fail and present the user with the failure message.  I didn't have time to fix it last night, and this morning was scratching my head trying to figure it out when I suddenly had what I call a "DUH!" moment.  

I think the problem with the validation is that the underlying engine is running the validation on each "entry" in the Multiline input.  Because I am separating each line with a @NewLine() character, when the user enters blank lines the server treats those as individual entries -which are blank.  So validation really is working correctly here.   But for my purposes, I don't care about each individual line.  All I care about is if there is ANY content in the field.  

So I simply changed the validation to a LENGTH test (with a minimum length of 2 characters).  It seems the server applies the length test to the entire contents of the input, not each line individually.  So my validation now works just fine.  Here is the new working XML:

<xp:inputTextarea
    id="subject1"
    rows="5"
    style="width:99%"
    value="${javascript:'#{compositeData.requestDocument.subject}'}"
    multipleSeparator="#{javascript:@NewLine()}">
    <xp:this.validators>
            <xp:validateLength
                    message="Please explain the issue for which you need help."
                    minimum="2">
            </xp:validateLength>
    </xp:this.validators>
</xp:inputTextarea>


Hope this helps!
-Devin.




Comments
No Comments Found

Discussion for this entry is now closed.