PDA

View Full Version : [CLOSED] How to deal with multiple validation groups?



exe
Nov 18, 2015, 8:56 PM
Hi,
how should I set up my page to be able to deal with multiple validation groups?

This is a very simple example of two fields with different validation groups. I need to validate only one group, before saving the form. I know, there is a Buttons collection in the FormPanel, and tried to use FormBind property along with ValidationGroup, but the later seems to be ignored.


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
}
}


private void Save(object sender, DirectEventArgs e)
{
throw new NotImplementedException();
}

</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title></title>

<script type="text/javascript">
</script>

</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FormPanel ID="FormPanel1" runat="server" Frame="True" MinHeight="200" Border="False" Layout="Form" BodyPadding="10" ButtonAlign="Left" AutoScroll="True" >
<Items>
<ext:TextField runat="server" ID="tf1" FieldLabel="Field1" ValidationGroup="vg1" AllowBlank="False"></ext:TextField>
<ext:TextField runat="server" ID="tf2" FieldLabel="Field2" ValidationGroup="vg2" AllowBlank="False"></ext:TextField>
</Items>
</ext:FormPanel>
<ext:Panel runat="server">
<Items>
<ext:Button runat="server" ID="btSave" Text="Validate only vg1">
<DirectEvents>
<Click OnEvent="Save" Before="return #{FormPanel}.validate();"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Panel>
</body>
</html>

So I tried to validate the fields manually, like this:


NS.getInvalidFields = function(form, validationGroup) {
var invalidFields = [];
Ext.suspendLayouts();
form.getForm().getFields().filterBy(function (field) {
if (field.validate()) return;
invalidFields.push(field);
});
Ext.resumeLayouts(true);
return invalidFields;
}

But I couldn't find the ValidationGroup property of the field.

Please let me know, what is the preferred approach to this problem.

Thank you!

Daniil
Nov 19, 2015, 1:21 PM
Hi @exe,

ValidationGroup is a native ASP.NET property and used for server side validation. Ext.NET doesn't use it for client side validation.


So I tried to validate the fields manually

Yes, it is a way to go.


But I couldn't find the ValidationGroup property of the field.

ValidationGroup is not rendered to client (since it is used by ASP.NET for server side validation).

Please use CustomConfig.

<ext:TextField ...>
<CustomConfig>
<ext:ConfigItem Name="validationGroup" Value="vg1" Mode="Value" />
</CustomConfig>
</ext:TextField>

exe
Nov 20, 2015, 5:38 PM
Ok, thanks!