Question
Kasikornbank Public Company Limited
TH
Last activity: 21 May 2020 0:54 EDT
How to create custom control like pxTextInput that can display error message below text box?
Hi,
I've created a custom control like pxTextInput to disable paste as below.
<pega:choose> <pega:when test="$mode-input"> <pega:include name="Messages"/> <input type=text onpaste="return false;" name="<pega:reference name="$this-name" />" value="<pega:reference name="$this-value" />" size="16" maxlength="16" <pega:include name="Attributes" /> <pega:include name="ClientValidation"/> id="<pega:reference name="$this-Definition(pyPropertyName)" mode="NORMAL" />" /> </pega:when> <pega:otherwise> <b><pega:reference name="$this-value"/></b> </pega:otherwise> </pega:choose>
My custom control can show missing require field error message correctly as expected like pxTextInput does. But if I enter the value that will be failed at validation, my custom control cannot show error message like pxTextInput. Please see picture in attached document.
How to set my custom control to behave like pxTextInput? I tried to find the jsp code of pxTextInput but I cannot find it.
Thank you,
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 20 May 2020 5:54 EDT
Pegasystems Inc.
AU
Hi Sitthanat,
Here, Please find the code below.
I have updated the code with a JS function which will remove the error message once the value entered in text box.
Extra lines added.
<script> function validatefloatinput(event){ let elm = event.target; $(elm).siblings('.errortext').empty(); $(elm).siblings('.errorwrapper').empty(); }
</script>
Input element modified with a onchange event. and error message tag updated with a class.
Hi Sitthanat,
Here, Please find the code below.
I have updated the code with a JS function which will remove the error message once the value entered in text box.
Extra lines added.
<script> function validatefloatinput(event){ let elm = event.target; $(elm).siblings('.errortext').empty(); $(elm).siblings('.errorwrapper').empty(); }
</script>
Input element modified with a onchange event. and error message tag updated with a class.
<input class="floating-input" placeholder=" " <pega:include name="ClientValidation"/> type="text" size="<pega:reference name="$save(strExpectedSize)" />" name="<pega:reference name="$this-name" />" id="<pega:reference name="$THIS-DEFINITION(pyPropertyName)" /><%= StringUtils.crossScriptingFilter(tools.getParamValue("pega_RLindex")) %>" value="<pega:reference name="$save(formattedNumber)" />" onchange="javascript:validatefloatinput(event)" /> <span class="highlight"></span> <label class="float-label"><%=tools.getParamValue("Label") %></label> <small style="color:red;" class= "errortext <% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
Full code below.
<style>
/**** floating-Lable style start ****/
small.errorwrapper{
float: right;
position: absolute;
right: 25px;
top: 6px;
}
small.errorwrapper .iconErrorDiv {
margin-left :0px !important;
}
.floating-label {
position:relative;
margin-bottom:20px;
margin-top:20px !important;
}
.floating-input , .floating-select {
font-size:14px;
padding:4px 4px !important;
display:block;
width:100%;
height:30px;
background-color: transparent !important;
border:none !important;
border-bottom:1px solid #757575 !important;
}
.floating-input:focus , .floating-select:focus {
outline:none !important;
border-bottom:2px solid #5264AE !important;
}
label.float-label {
color:#999 !important;
font-size:14px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:5px;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
.floating-input:focus ~ label, .floating-input:not(:placeholder-shown) ~ label {
top:-18px;
font-size:14px;
color:#5264AE !important;
}
.floating-select:focus ~ label , .floating-select:not([value=""]):valid ~ label {
top:-18px;
font-size:14px;
color:#5264AE;
}
/* active state */
.floating-input:focus ~ .bar:before, .floating-input:focus ~ .bar:after, .floating-select:focus ~ .bar:before, .floating-select:focus ~ .bar:after {
width:50%;
}
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.floating-textarea {
min-height: 30px;
max-height: 260px;
overflow:hidden;
overflow-x: hidden;
}
/* highlighter */
.highlight {
position:absolute;
height:50%;
width:100%;
top:15%;
left:0;
pointer-events:none;
opacity:0.5;
}
/* active state */
.floating-input:focus ~ .highlight , .floating-select:focus ~ .highlight {
-webkit-animation:inputHighlighter 0.3s ease;
-moz-animation:inputHighlighter 0.3s ease;
animation:inputHighlighter 0.3s ease;
}
/* animation */
@-webkit-keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
@-moz-keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
@keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
</style>
<script>
function validatefloatinput(event){
let elm = event.target;
$(elm).siblings('.errortext').empty();
$(elm).siblings('.errorwrapper').empty();
}
</script>
<pega:choose>
<pega:when test='param.Size != ""'>
<pega:save name="strExpectedSize" ref="param.Size" />
</pega:when>
<pega:when java='<%= !tools.getDictionary().fromDefinition(tools.getActive(), "pyExpectedSize").equals("") %>'>
<% tools.putSaveValue("strExpectedSize", tools.getDictionary().fromDefinition(tools.getActive(), "pyExpectedSize")); %>
</pega:when>
<pega:otherwise>
<pega:save name="strExpectedSize" value="8" />
</pega:otherwise>
</pega:choose>
<pega:save name="strExpectedSize" value="8" />
<pega:when test='param.ReadOnlySmartInfo != "" || param.ReadWriteSmartInfo != ""'>
<pega:include name="StartSmartField" />
</pega:when>
<%
ClipboardProperty curProp = tools.getActive();
String strValue="";
String messageOnProp = curProp.getMessages();
boolean propHasValidValue = curProp.hasValidValue();
String messageOnPropAfter = curProp.getMessages();
if(messageOnPropAfter.equals("") && !messageOnProp.equals("")){
curProp.addMessage(messageOnProp);
}
tools.putSaveValue("formattedNumber",tools.getActiveValue());
strValue = tools.getActiveValue();
strValue = StringUtils.crossScriptingFilter(strValue);
tools.putSaveValue("result", strValue);
%>
<pega:choose>
<pega:when java='<%=tools.getParamAsBoolean(PropertyInfo.TYPE_TRUEFALSE,"CalculatedValue")%>'>
<%-- YOU MUST PASS ALONG ALL PARAMETERS HERE!!!! --%>
<SPAN nowrap>
<pega:include name="Messages"/>
<span id="CV" name="<pega:reference name='$this-name' mode="NORMAL" />" RHP_NAME="<pega:reference name='$stream-definition(pyStreamName)' mode="NORMAL" />" class='dataLabelCalculatedValue' >
<%=tools.getSaveValue("result")%>
</SPAN>
</pega:when>
<pega:otherwise>
<pega:choose>
<pega:when test='$mode-input'>
<SPAN nowrap>
<div class="floating-label">
<small class="errorwrapper"> <pega:include name="Messages"/></small>
<input class="floating-input" placeholder=" " <pega:include name="ClientValidation"/> type="text"
size="<pega:reference name="$save(strExpectedSize)" />"
name="<pega:reference name="$this-name" />"
id="<pega:reference name="$THIS-DEFINITION(pyPropertyName)" /><%= StringUtils.crossScriptingFilter(tools.getParamValue("pega_RLindex")) %>"
value="<pega:reference name="$save(formattedNumber)" />"
onchange="javascript:validatefloatinput(event)"
/>
<span class="highlight"></span>
<label class="float-label"><%=tools.getParamValue("Label") %></label>
<small style="color:red;" class= "errortext <% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
</div>
</SPAN>
</pega:when>
<pega:otherwise>
<%=tools.getSaveValue("result")%>
</pega:otherwise>
</pega:choose>
</pega:otherwise>
</pega:choose>
<pega:when test='param.ReadOnlySmartInfo != "" || param.ReadWriteSmartInfo != ""'>
<pega:include name="EndSmartField" />
</pega:when>
Updated: 14 May 2020 6:07 EDT
Pegasystems Inc.
AU
Hi Sitthanat,
Here i have created a customer control before similar to text input, Please use this code to display the error message.
Hi Sitthanat,
Here i have created a customer control before similar to text input, Please use this code to display the error message.
<pega:choose>
<pega:when test='param.Size != ""'>
<pega:save name="strExpectedSize" ref="param.Size" />
</pega:when>
<pega:when java='<%= !tools.getDictionary().fromDefinition(tools.getActive(), "pyExpectedSize").equals("") %>'>
<% tools.putSaveValue("strExpectedSize", tools.getDictionary().fromDefinition(tools.getActive(), "pyExpectedSize")); %>
</pega:when>
<pega:otherwise>
<pega:save name="strExpectedSize" value="50" />
</pega:otherwise>
</pega:choose>
<%
ClipboardProperty curProp = tools.getActive();
String strValue="";
String messageOnProp = curProp.getMessages();
boolean propHasValidValue = curProp.hasValidValue();
String messageOnPropAfter = curProp.getMessages();
if(messageOnPropAfter.equals("") && !messageOnProp.equals("")){
curProp.addMessage(messageOnProp);
}
tools.putSaveValue("formattedNumber",tools.getActiveValue());
strValue = tools.getActiveValue();
strValue = StringUtils.crossScriptingFilter(strValue);
tools.putSaveValue("result", strValue);
%>
<SPAN nowrap>
<div class="floating-label">
<small class="errorwrapper"> <pega:include name="Messages"/></small>
<input class="floating-input <% if(messageOnPropAfter.length()>0){ %> error <% } %> " placeholder=" " <pega:include name="ClientValidation"/> type="text"
size="<pega:reference name="$save(strExpectedSize)" />"
name="<pega:reference name="$this-name" />"
id="<pega:reference name="$THIS-DEFINITION(pyPropertyName)" /><%= StringUtils.crossScriptingFilter(tools.getParamValue("pega_RLindex")) %>"
value="<pega:reference name="$save(formattedNumber)" />">
<span class="highlight"></span>
<label class="float-label "><%=tools.getParamValue("Label") %></label>
<small class= "<% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
</div>
</SPAN>
-
Sitthanat Champerat
Kasikornbank Public Company Limited
TH
Hi Karma,
Thank you for your information. I use your code and do some modification to fit my requirement. It can show error message but it's behavior still does not like pxTextInput. I put the detail in attached document.
Thank you
Pegasystems Inc.
AU
In the custom control on blur event of the text input, you need to call a javascript function to check if the input box is having a value or not, If its having a value you need to clear error message which is inside the <small> tag.
This line.
<small class= "<% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
let me know if you will be able to do that, or i can help you out.
Kasikornbank Public Company Limited
TH
I've already added this line to my custom control. It won't show the error message if there is no error message in that property and it will show the error message if there is an error message as expected.
But for pxTextInput it will remove error message on screen immediately when we update the value without submit so I want my custom control to do the same thing.
I don't know how pxTextInput does. I look at the clipboard, the error message is still in the clipboard but it will not show the message if I update the value or just click at pxTextInput area.
============================================================================
<small style="color:red;font-size:14px;" class= "<% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
Pegasystems Inc.
AU
Yes, We do clear the message at front end using javascript.
That's why i have asked you to configure an event listener to the control, and after entering the text when you blurred out, Just clear the error message from front end. The behavior will be same like pxTextInput.
This HTML element holds the error message in UI, You need to clear the text from it when blurred out, using javascript.
<small class= "<% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
Kasikornbank Public Company Limited
TH
Can you help me to show the sample of how to create javascript to clear the error message?
Thank you,
Accepted Solution
Updated: 20 May 2020 5:54 EDT
Pegasystems Inc.
AU
Hi Sitthanat,
Here, Please find the code below.
I have updated the code with a JS function which will remove the error message once the value entered in text box.
Extra lines added.
<script> function validatefloatinput(event){ let elm = event.target; $(elm).siblings('.errortext').empty(); $(elm).siblings('.errorwrapper').empty(); }
</script>
Input element modified with a onchange event. and error message tag updated with a class.
Hi Sitthanat,
Here, Please find the code below.
I have updated the code with a JS function which will remove the error message once the value entered in text box.
Extra lines added.
<script> function validatefloatinput(event){ let elm = event.target; $(elm).siblings('.errortext').empty(); $(elm).siblings('.errorwrapper').empty(); }
</script>
Input element modified with a onchange event. and error message tag updated with a class.
<input class="floating-input" placeholder=" " <pega:include name="ClientValidation"/> type="text" size="<pega:reference name="$save(strExpectedSize)" />" name="<pega:reference name="$this-name" />" id="<pega:reference name="$THIS-DEFINITION(pyPropertyName)" /><%= StringUtils.crossScriptingFilter(tools.getParamValue("pega_RLindex")) %>" value="<pega:reference name="$save(formattedNumber)" />" onchange="javascript:validatefloatinput(event)" /> <span class="highlight"></span> <label class="float-label"><%=tools.getParamValue("Label") %></label> <small style="color:red;" class= "errortext <% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
Full code below.
<style>
/**** floating-Lable style start ****/
small.errorwrapper{
float: right;
position: absolute;
right: 25px;
top: 6px;
}
small.errorwrapper .iconErrorDiv {
margin-left :0px !important;
}
.floating-label {
position:relative;
margin-bottom:20px;
margin-top:20px !important;
}
.floating-input , .floating-select {
font-size:14px;
padding:4px 4px !important;
display:block;
width:100%;
height:30px;
background-color: transparent !important;
border:none !important;
border-bottom:1px solid #757575 !important;
}
.floating-input:focus , .floating-select:focus {
outline:none !important;
border-bottom:2px solid #5264AE !important;
}
label.float-label {
color:#999 !important;
font-size:14px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:5px;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
.floating-input:focus ~ label, .floating-input:not(:placeholder-shown) ~ label {
top:-18px;
font-size:14px;
color:#5264AE !important;
}
.floating-select:focus ~ label , .floating-select:not([value=""]):valid ~ label {
top:-18px;
font-size:14px;
color:#5264AE;
}
/* active state */
.floating-input:focus ~ .bar:before, .floating-input:focus ~ .bar:after, .floating-select:focus ~ .bar:before, .floating-select:focus ~ .bar:after {
width:50%;
}
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.floating-textarea {
min-height: 30px;
max-height: 260px;
overflow:hidden;
overflow-x: hidden;
}
/* highlighter */
.highlight {
position:absolute;
height:50%;
width:100%;
top:15%;
left:0;
pointer-events:none;
opacity:0.5;
}
/* active state */
.floating-input:focus ~ .highlight , .floating-select:focus ~ .highlight {
-webkit-animation:inputHighlighter 0.3s ease;
-moz-animation:inputHighlighter 0.3s ease;
animation:inputHighlighter 0.3s ease;
}
/* animation */
@-webkit-keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
@-moz-keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
@keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
</style>
<script>
function validatefloatinput(event){
let elm = event.target;
$(elm).siblings('.errortext').empty();
$(elm).siblings('.errorwrapper').empty();
}
</script>
<pega:choose>
<pega:when test='param.Size != ""'>
<pega:save name="strExpectedSize" ref="param.Size" />
</pega:when>
<pega:when java='<%= !tools.getDictionary().fromDefinition(tools.getActive(), "pyExpectedSize").equals("") %>'>
<% tools.putSaveValue("strExpectedSize", tools.getDictionary().fromDefinition(tools.getActive(), "pyExpectedSize")); %>
</pega:when>
<pega:otherwise>
<pega:save name="strExpectedSize" value="8" />
</pega:otherwise>
</pega:choose>
<pega:save name="strExpectedSize" value="8" />
<pega:when test='param.ReadOnlySmartInfo != "" || param.ReadWriteSmartInfo != ""'>
<pega:include name="StartSmartField" />
</pega:when>
<%
ClipboardProperty curProp = tools.getActive();
String strValue="";
String messageOnProp = curProp.getMessages();
boolean propHasValidValue = curProp.hasValidValue();
String messageOnPropAfter = curProp.getMessages();
if(messageOnPropAfter.equals("") && !messageOnProp.equals("")){
curProp.addMessage(messageOnProp);
}
tools.putSaveValue("formattedNumber",tools.getActiveValue());
strValue = tools.getActiveValue();
strValue = StringUtils.crossScriptingFilter(strValue);
tools.putSaveValue("result", strValue);
%>
<pega:choose>
<pega:when java='<%=tools.getParamAsBoolean(PropertyInfo.TYPE_TRUEFALSE,"CalculatedValue")%>'>
<%-- YOU MUST PASS ALONG ALL PARAMETERS HERE!!!! --%>
<SPAN nowrap>
<pega:include name="Messages"/>
<span id="CV" name="<pega:reference name='$this-name' mode="NORMAL" />" RHP_NAME="<pega:reference name='$stream-definition(pyStreamName)' mode="NORMAL" />" class='dataLabelCalculatedValue' >
<%=tools.getSaveValue("result")%>
</SPAN>
</pega:when>
<pega:otherwise>
<pega:choose>
<pega:when test='$mode-input'>
<SPAN nowrap>
<div class="floating-label">
<small class="errorwrapper"> <pega:include name="Messages"/></small>
<input class="floating-input" placeholder=" " <pega:include name="ClientValidation"/> type="text"
size="<pega:reference name="$save(strExpectedSize)" />"
name="<pega:reference name="$this-name" />"
id="<pega:reference name="$THIS-DEFINITION(pyPropertyName)" /><%= StringUtils.crossScriptingFilter(tools.getParamValue("pega_RLindex")) %>"
value="<pega:reference name="$save(formattedNumber)" />"
onchange="javascript:validatefloatinput(event)"
/>
<span class="highlight"></span>
<label class="float-label"><%=tools.getParamValue("Label") %></label>
<small style="color:red;" class= "errortext <% if(messageOnPropAfter.length()>0){ %> error <% } %> " > <%= messageOnPropAfter %></small>
</div>
</SPAN>
</pega:when>
<pega:otherwise>
<%=tools.getSaveValue("result")%>
</pega:otherwise>
</pega:choose>
</pega:otherwise>
</pega:choose>
<pega:when test='param.ReadOnlySmartInfo != "" || param.ReadWriteSmartInfo != ""'>
<pega:include name="EndSmartField" />
</pega:when>
-
Sitthanat Champerat
Kasikornbank Public Company Limited
TH
Thank you, I can use your script with my custom control to clear the error message as I expected.
Kasikornbank Public Company Limited
TH
This is my custom control
<script> function validatefloatinput(event){ let elm = event.target; $(elm).siblings('.iconError').empty(); $(elm).siblings('.iconErrorDiv').empty(); }
</script>
<% ClipboardProperty curProp = tools.getActive(); String messageOnPropAfter = curProp.getMessages(); %>
This is my custom control
<script> function validatefloatinput(event){ let elm = event.target; $(elm).siblings('.iconError').empty(); $(elm).siblings('.iconErrorDiv').empty(); }
</script>
<% ClipboardProperty curProp = tools.getActive(); String messageOnPropAfter = curProp.getMessages(); %>
<pega:choose> <pega:when test="$mode-input"> <input type=text onpaste="return false;" name="<pega:reference name="$this-name" />" value="<pega:reference name="$this-value" />" size="16" maxlength="16" <pega:include name="Attributes" /> <pega:include name="ClientValidation"/> id="<pega:reference name="$this-Definition(pyPropertyName)" mode="NORMAL" />" onblur="javascript:validatefloatinput(event)" /> <div id="$this-name" class="iconErrorDiv dynamic-icon-error-div"> <span class="iconError dynamic-icon-error" errid="" id="PegaRULESErrorFlag"> <%= messageOnPropAfter %> </span> </div> </pega:when> <pega:otherwise> <b><pega:reference name="$this-value"/></b> </pega:otherwise> </pega:choose>
Pegasystems Inc.
AU
Great!!!,
I am glad that I could help. Please feel free to ping me if you need any further support in future.