Xpages conditional validation: make a field required only if report is being submitted as final

Posted by Randal Oulton on Stack Overflow See other posts from Stack Overflow or by Randal Oulton
Published on 2014-06-12T19:20:38Z Indexed on 2014/06/12 21:25 UTC
Read the original article Hit count: 378

Filed under:
|

Doing server-side Xpages conditional validation....

I want the follow validation to kick in only if the Report.Status field = 'Final'. (The users are allowed to submit the report as draft and come back and finish it later, when they submit as draft we don't want to make the fields required.)

How would I go about this?

    <xp:inputTextarea style="width:75%" value="#{Report.Agenda}" id="Agenda">
                            <xp:this.validators>
                    <xp:validateRequired
                        message="Question 1 can't be blank">
                    </xp:validateRequired><!-- (1)  -->
                </xp:this.validators>
    </xp:inputTextarea>

Tried this, didn't work, was still required even if Status field not set to final :{

    <xp:inputTextarea style="width:75%" value="#{Report.Agenda}" id="Agenda" defaultValue="5 year agenda">
                            <xp:this.validators>
                    <xp:validateRequired message="Question 1 can't be blank"></xp:validateRequired><!-- (1)  -->
                    <xp:validateExpression message="Question 1 can't be blank">
        <xp:this.expression><![CDATA[#{javascript:
            if (Report.getItemValueString('Status')!='Final') {
                return true;
            }
        else {
        return false;
        }
        }]]></xp:this.expression>
    </xp:validateExpression>
                </xp:this.validators>
    </xp:inputTextarea>

© Stack Overflow or respective owner

Related posts about validation

Related posts about xpages