Fórum

<aui-Validator> is not working

anand gopalan, modificado 10 Anos atrás.

<aui-Validator> is not working

Expert Postagens: 442 Data de Entrada: 02/03/12 Postagens Recentes
I want vehicle number text field should not empty I have written like below and i didn't get any error, but validation is not happen, what wrong in my code.
below Validation is not working,

view.jsp

<tr>
<td>Vehicle Number</td>
<td colspan="6">


<aui:input name="t02Vechileno" type="text" label="">
<aui:validator name="required" errorMessage="this-field-is-required" />

</aui:input>
</td>

</tr>
thumbnail
Manali Lalaji, modificado 10 Anos atrás.

RE: <aui-Validator> is not working

Expert Postagens: 362 Data de Entrada: 09/03/10 Postagens Recentes
Hi Anand,

Actually it should work.

You might have already defined the taglib:
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>

Sample code:

<aui:form method="POST" name="fm" id="fm">
<aui:layout>
<aui:column cssclass="aui-w25">
<aui:input name="field1" first="<%=true %>">
<!-- Example with multiple validators -->

       <!-- Make the field required.  If the field is empty, form will not submit -->
       <aui:validator name="required" />

       <!-- Only allow digits in the field -->
       <aui:validator name="digits" />

       <!-- Make sure field value is between 8 and 50 characters in length -->
       <aui:validator name="range">
           [8,50]
       </aui:validator>
     
   </aui:input>
   <aui:button-row><aui:button type="submit" /></aui:button-row>
 
</aui:column>
</aui:layout></aui:form>


Thanks,
Manali
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: <aui-Validator> is not working

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
May be it doesn't work for LR 6.0.5 or below version
anand gopalan, modificado 10 Anos atrás.

RE: <aui-Validator> is not working

Expert Postagens: 442 Data de Entrada: 02/03/12 Postagens Recentes
Hi,

Here I have attached full view.jsp code and I want when form submit, any of the text field should not be empty and I using AUI validator tag. But it is not working. Please help me.

Did I miss anything configuration, etc....
...

Environment: Liferay6.1.0, CE and Browser IE 9, Firfox 22.0 and Safri 5.1.7.


<%
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>


<%@ page import="com.test.model.EMP_DETAIL"%>
<%@ page import="com.test.service.EMP_VEICHLE_TYPELocalServiceUtil" %>
<%@ page import="com.test.model.EMP_VEICHLE_TYPE"%>
<%@ page import="com.test.model.EMP_VEICHLE_TYPEModel"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="javax.portlet.RenderRequest"%>
<portlet:defineObjects />




<html>
<head>
<title>Travel Details</title>


</head>

<script type="text/javascript" >


function addRow(tableID) {

//var uniqueId=1;

var rowid = window.document.getElementById(1).id;
alert("First row id-->"+rowid);
var table = document.getElementById(tableID);

var rowCount = table.rows.length;

alert("value of rowCount"+rowCount);

var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name="selectDel[]"+rowCount;


//cell1.appendChild(element1);


var cell2 = row.insertCell(1) ;
var element2 = document.createElement("input");
element2.type = "text";
//element2.name = "t02Traveldate[]" +rowCount;
element2.name = "t02Traveldate" +rowCount;


//cell2.appendChild(element2);

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "t02Travelfrom"+rowCount;
element3.value='';
//cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "t02Travelto"+rowCount;
//cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "t02Landmark"+rowCount;
//cell5.appendChild(element5);

var cell6 = row.insertCell(5);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "t02Totalkm"+rowCount;
//cell6.appendChild(element6);

var uniqueId;
/* Start */
for (var i=2;rowCount>7;i++){

uniqueId = i;
//uniqueId=rowCount;
alert("Value of unique id-->"+uniqueId);

cell1.appendChild(element1);
cell2.appendChild(element2);
cell3.appendChild(element3);
cell4.appendChild(element4);
cell5.appendChild(element5);
cell6.appendChild(element6);

document.getElementById("hdn").value=uniqueId;
document.frmaddTravelDetails.submit();


}
/* End */

}
function send(tableID) {
alert("call send function");
var table = document.getElementById(tableID);
var rowCount1 = table.rows.length;
document.<portlet:namespace/>frmaddTravelDetails.<portlet:namespace/>hdn.value = ""+rowCount1;
document.<portlet:namespace/>frmaddTravelDetails.submit();

}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for(var i=0; i<rowCount; i++) {
var row = table.rows;
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {


if(rowCount <= 8) {

alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}


}
}catch(e) {
alert(e);
}
}
function Blank_TextField_Validator()
{
// Check whether the value of the element
// text_name from the form named text_form is null
if (!frmaddTravelDetails.t02Vechileno.value)
{
// If it is display and alert box
alert("Please fill in the vehicle no text field.");
// Place the cursor on the field for revision
frmaddTravelDetails.t02Vechileno.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
return (true);
}

</script>

<body>
<portlet:actionURL name="processAction" var="processActionURL"/>

<%
EMP_DETAIL empDetail=(EMP_DETAIL) request.getAttribute("empDetail");
%>

<aui:form name="frmaddTravelDetails" id="frmaddTravelDetails" action="<%=processActionURL.toString()%>" method="post">
<table id="dataTable" border="1">

<tr>
<th colspan="7" style="text-align:center;">Employee Travel Details</th></tr>
<tr>
<td>Employee ID</td>
<td colspan="6">

<aui:input name="t02Emplid" label="" type="text" value='<%=empDetail.getM01Emplid() %>' /></td>
</tr>
<tr>
<td>Employee Name</td>
<td colspan="6"><aui:input name="t02Ename" label="" type="text" value='<%=empDetail.getM01Empname() %>' /></td>
</tr>
<tr>
<td>Vehicle Type</td>
<td colspan="6">

<aui:select name="t02Vechiletype" label="" id="selectedVehicle">

<c:forEach items="${empVehicleList}" var="empVehicle" >

<aui:option value="${empVehicle.m04Vehicle_Type}" >${empVehicle.m04Vehicle_Type}</aui:option>

</c:forEach>

</aui:select>
</td>
</tr>
<tr>
<td>Approver</td>
<td colspan="6">
<aui:select name="t02Approver" label="" id="selectedApprover">


<% List<String> listMangers = (List<String>) request.getAttribute("listManagers");

Set<String> set = new HashSet<String>(listMangers);
System.out.println("SIZE "+set.size());
for (String managerList : set){
%>

<aui:option value="<%=managerList%>" ><%=managerList%></aui:option>

<%
}
%>



</aui:select>
</td>
</tr>
<tr>
<td>Vehicle Number</td>
<td colspan="6">


<aui:input name="t02Vechileno" id="t02Vechileno" type="text" label="" value="" >
<aui:validator name="required" errorMessage="this-field-is-required"/>
</aui:input>

</td>

</tr>
<tr>
<td>Select</td>

<td>Date(dd/mm/yyyy)</td>
<td>From</td>
<td>To</td>
<td>Landmark</td>
<td colspan="6">Total KM</td>
</tr>
<tr id=1>
<td><aui:input name="selectDel" type="checkbox" label=""/></TD>

<td>
<aui:input name="t02Traveldate" type="text" value="" label="">

</aui:input>
<!--
<liferay-ui:input-date formName="t02Traveldate" yearRangeStart="1970"
yearRangeEnd="2100" yearValue="2013" monthValue="4" dayValue="9"
dayParam="d1" monthParam="m1" yearParam="y1" />-->
</td>
<td>
<aui:input name="t02Travelfrom" type="text" label="" value="">

<aui:validator name="required" errorMessage="this-field-is-required"/>

</aui:input>

</td>
<td>
<aui:input name="t02Travelto" type="text" label="" value="">

<aui:validator name="required" errorMessage="this-field-is-required"/>

</aui:input>

</td>
<td>
<aui:input name="t02Landmark" type="text" label="" value="">

<aui:validator name="required" errorMessage="this-field-is-required"/>

</aui:input>


</td>
<td>
<aui:input name="t02Totalkm" type="text" label="" maxlength="7" value="" onkeypress="IsDecimal(event);">

<aui:validator name="required" errorMessage="this-field-is-required"/>

</aui:input>


<input type="hidden" name="hdn" id="hdn" />


</td>


</tr>

</table>

<table id="dataTable1" border="1">
<tr>
<td colspan="7" style="text-align:center;"><aui:button name="submitAction" type="submit" value="Apply" /></td>
<td><aui:button name="addRow" type="button" value="Add Row" onclick="addRow('dataTable')" /></td>

<td><aui:button name="deleteRow" type="button" value="Delete Row" onclick="deleteRow('dataTable')" /></td>

</tr>
</table>
</aui:form>
</body>
</html>
anand gopalan, modificado 10 Anos atrás.

RE: <aui-Validator> is not working

Expert Postagens: 442 Data de Entrada: 02/03/12 Postagens Recentes
Hi All,

Due to JavaScript error AUI Validator was not working, Now I fixed the JavaScript error and its working now.

I am creating dynamic rows and its has 5 text fields. Now how can I validate this text field. Please help me.
y mougenel, modificado 7 Anos atrás.

RE: <aui-Validator> is not working

New Member Postagens: 3 Data de Entrada: 08/07/16 Postagens Recentes
Hi there,
I had a similar problem. I fixed it by putting a name to the aui:form containing the aui:input.
I don't know why validators requires a form name, yet it works.

I hope it works for you