Jan 31, 2014, 3:45 PM
[CLOSED] VType and form validation
Hi,
I'm trying to implement a simple VType validation on a DateField. I'd like to understand how to do it properly so that it gets wired into the overall form validation call. So far, isValid() seems to disregard the custom validation logic returning "true" with the date input being, for example, "1/1/1001". Please suggest how to handle it properly or if there're any flaws in my approach.
I'm trying to implement a simple VType validation on a DateField. I'd like to understand how to do it properly so that it gets wired into the overall form validation call. So far, isValid() seems to disregard the custom validation logic returning "true" with the date input being, for example, "1/1/1001". Please suggest how to handle it properly or if there're any flaws in my approach.
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET Example</title>
<ext:ResourcePlaceHolder runat="server" Mode="Script" />
<script type="text/javascript">
Ext.apply(Ext.form.VTypes, {
mydaterange: function (val, field) {
var date = field.parseDate(val);
if (!date) {
return true; //instead of 'return;' - it was breaking a validation process
}
var today = new Date();
if (date < new Date("1/1/1753") || date > new Date(today.getFullYear(), today.getMonth(), today.getDate())) {
return false;
}
return true;
}
});
var validate = function () {
var valid = Form1.getForm().isValid();
Ext.Msg.alert("Validation", valid ? "Valid" : "Invalid");
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:FormPanel runat="server" ID="Form1" ButtonAlign="Left">
<Items>
<ext:DateField
ID="DateField1"
runat="server"
Width="100"
FieldLabel="From"
Vtype="mydaterange" />
</Items>
<Buttons>
<ext:Button runat="server" Text="Validate">
<Listeners>
<Click Handler="validate();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</form>
</body>
</html>
Last edited by Daniil; Feb 03, 2014 at 4:18 AM.
Reason: [CLOSED]