lotus notes - validate edit box input text length on xPage -


when enable field length validation validates when submit form...

<?xml version="1.0" encoding="utf-8"?> 

<xp:inputtext id="inputtext1">     <xp:this.validators>         <xp:validatelength maximum="20"             message="you can input max 20 characters">         </xp:validatelength>     </xp:this.validators> </xp:inputtext> <xp:message id="message1" for="inputtext1"></xp:message> 

so how show error message once user typed in 21st character? assume need code csjs...

add client side event handler "onkeyup" inputtext control:

    <xp:eventhandler         event="onkeyup"         submit="false">         <xp:this.script><![cdata[             thisevent.srcelement.value = thisevent.srcelement.value.substring(0, 20)         ]]></xp:this.script>     </xp:eventhandler> 

it shortens text max length if necessary.

you can show message alert

            var element = thisevent.srcelement;             if (element.value.length > 20) {                 element.value = element.value.substring(0, 20);                 alert("you can input max 20 characters");             } 

or can add client message text field xpages , fill message whenever max length reached

<xp:inputtext id="inputtext1">     <xp:this.validators>         <xp:validatelength  maximum="20"             message="you can input max 20 characters">         </xp:validatelength>     </xp:this.validators>     <xp:eventhandler         event="onkeyup"         submit="false">         <xp:this.script><![cdata[             var element = thisevent.srcelement;             var message = document.getelementbyid("#{id:clientmessage}");             if (element.value.length > 20) {                 element.value = element.value.substring(0, 20);                 message.innerhtml = "you can input max 20 characters";             } else {                 message.innerhtml = "";             }         ]]></xp:this.script>     </xp:eventhandler>     </xp:inputtext> <xp:text id="clientmessage" value="" /> 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -