Xpages conditional validation: make a field required only if report is being submitted as final
- by Randal Oulton
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>