This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



May 31, 2012, 8:59 PM
15 Posts

validation in server side javascript for the forms on xpages.

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 2
i want to show a validation pop on xpages in server side javascript .......
Jun 1, 2012, 9:39 AM
26 Posts
Re: validation in server side javascript for the forms on xpages.
You can use following code for validating fields on the xpage:
 
if(getComponent("PersonName").getValue()=="" || getComponent("PersonName").getValue()==null)
      { ValidateMsg= ValidateMsg + " Person Name cannot be blank" + "\n"
          return false;
           }
     }
    
     if(getComponent("Email").getValue()=="" || getComponent("Email").getValue()==null)
      { ValidateMsg= ValidateMsg + " Employee Email cannot be blank" + "\n"  }
    
    if(getComponent("StartDate").getValue()==null )
      { ValidateMsg= ValidateMsg + " Start Date cannot be blank" + "\n"  }
 
It just adds the validation message to a field ValidateMsg and then this field is passed to a custom control to display the warning to user.
 
 
Below is the code for the Custom control I had used to display the message box:
 
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex" dojoTheme="true"
    dojoParseOnLoad="true" dojoForm="true">

    <xp:this.resources>
        <xp:dojoModule name="dijit.form.Button"></xp:dojoModule>
    </xp:this.resources>

    <xe:dialog id="MsgBoxDialog" title="Message">
        <xp:panel>
            <xp:inputText id="action"
                style="width:75.0px; display:none">
            </xp:inputText>
            <xp:table style="width:100%">
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td>
                        <xp:image id="image1" style="height:42.0px">
                            <xp:this.url><![CDATA[#{javascript:if (getComponent("ValidateMsgBox").getValue()!= null) { return("/fail.png");}
else {return("/success.png");}}]]></xp:this.url>
                        </xp:image>
                    </xp:td>
                    <xp:td>
                        <xp:text escape="true" id="MsgBox">

                        </xp:text>
                        <xp:inputTextarea id="ValidateMsgBox"
                            readonly="true">
                            <xp:this.multipleSeparator><![CDATA["\n"]]></xp:this.multipleSeparator>
                        </xp:inputTextarea>
                    </xp:td>




                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td align="center">
                        <xp:button value=" OK " id="button2"
                            style="text-align:center;width:56.0px">
                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="complete" id="eventHandler1">
                                <xp:this.action><![CDATA[#{javascript:getComponent("MsgBoxDialog").hide()

}]]></xp:this.action>
                            </xp:eventHandler>
                        </xp:button>
                    </xp:td>




                </xp:tr>
            </xp:table>


        </xp:panel>



    </xe:dialog>
    <xp:br></xp:br></xp:view>


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal