Foros de discusión

AUI:validator in loop

zhang Mr, modificado hace 7 años.

AUI:validator in loop

New Member Mensajes: 3 Fecha de incorporación: 21/03/17 Mensajes recientes
It is validating only first element in the loop


		       <c:foreach items="${kcInfo }" var="kc">
		       	 <c:if test="${s[0]==kc[0] }">
			      <aui:input type="text" name="kpiCount" id="kpiCount" value="${kc[1]}">
			      &lt;%--  <aui:validator name="required" /> --%&gt;
			        <aui:validator name="custom" errormessage="kpicount-error">
			    	 function (val, fieldNode, ruleValue) {
		                var value = document.getElementById('<portlet:namespace />kpiCount').value;
	                    var regex = /^[0-9]*[0-9][0-9]*$/;
						 if(regex.test(value)){					
			        		return true;
			             } 
			             return false;
			         } 
					</aui:validator>
			       </aui:input>
			        	<!-- <span style="color:red;" id="notice"></span> -->			 
		         </c:if>	        	
		       </c:foreach>
	       
thumbnail
Mohammad Azharuddin, modificado hace 7 años.

RE: AUI:validator in loop

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
Try this <td>
<c:forEach items="${kcInfo }" var="kc" >
<c:if test="${s[0]==kc[0] }">
<aui:input type="text" name="kpiCount${kc[1]}" id="kpiCount" value="${kc[1]}">
<%-- name="kpiCount${kc[1]}" or name="kpiCount${kc[0]}" for each element we need to pass the different value for name attribute --%>
<%-- <aui:validator name="required" /> --%>
<aui:validator name="custom" errorMessage="kpicount-error">
function (val, fieldNode, ruleValue) {
var value = document.getElementById('<portlet:namespace />kpiCount').value;
var regex = /^[0-9]*[0-9][0-9]*$/;
if(regex.test(value)){
return true;
}
return false;
}
</aui:validator>
</aui:input>
<!-- <span style="color:red;" id="notice"></span> -->
</c:if>
</c:forEach>
</td>
zhang Mr, modificado hace 7 años.

RE: AUI:validator in loop

New Member Mensajes: 3 Fecha de incorporación: 21/03/17 Mensajes recientes
Mohammad Azharuddin:
Try this <td>
<c:forEach items="${kcInfo }" var="kc" >
<c:if test="${s[0]==kc[0] }">
<aui:input type="text" name="kpiCount${kc[1]}" id="kpiCount" value="${kc[1]}">
<%-- name="kpiCount${kc[1]}" or name="kpiCount${kc[0]}" for each element we need to pass the different value for name attribute --%>
<%-- <aui:validator name="required" /> --%>
<aui:validator name="custom" errorMessage="kpicount-error">
function (val, fieldNode, ruleValue) {
var value = document.getElementById('<portlet:namespace />kpiCount').value;
var regex = /^[0-9]*[0-9][0-9]*$/;
if(regex.test(value)){
return true;
}
return false;
}
</aui:validator>
</aui:input>
<!-- <span style="color:red;" id="notice"></span> -->
</c:if>
</c:forEach>
</td>





still doesn't workemoticon
can't validate the first one yet!
Thanks anyway!
thumbnail
Mohammad Azharuddin, modificado hace 7 años.

RE: AUI:validator in loop

Expert Mensajes: 492 Fecha de incorporación: 17/09/12 Mensajes recientes
bottom line is that , when u add a <aui:input in loop make sure that the name attribute has unique value . That value u need to pass dynamically