PDA

View Full Version : [CLOSED] FieldContainer CombineErrors="true"



cwolcott
Sep 28, 2012, 5:50 PM
My basic question, without an example is:

If I have a ext:FieldContainer with the attribute CombineErrors="true". Should the combineError show errors for hidden fields within the container?

The field in question is originally hidden and does not allowBlanks. Based on the user selecting a combobox item the field is shown and the user begins to edit it, but then changes their mind and selects a different item in the combobox which hides the field. But now the FieldContainer error says there is an error on the hidden field.

I would prefer that hidden fields should not be analyzed as part of the CombineErrors. Changing it to visible="false" instead of hidden="true" causes other issues.

Daniil
Sep 28, 2012, 6:39 PM
Hi Chris,

We can suggest the following solution.

Example

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

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

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var onHide = function (field) {
field.originalGetErrors = field.getErrors;
field.getErrors = function () { return []; };
field.validate();
};

var onShow = function (field) {
field.getErrors = field.originalGetErrors;
delete field.originalGetErrors;
field.validate();
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FieldContainer
runat="server"
CombineErrors="true"
MsgTarget="Under"
Width="300"
Layout="HBoxLayout" >
<Items>
<ext:TextField ID="TextField1" runat="server" AllowBlank="false">
<Listeners>
<Hide Fn="onHide" />
<Show Fn="onShow" />
</Listeners>
</ext:TextField>
<ext:TextField runat="server" AllowBlank="false" />
</Items>
</ext:FieldContainer>

<ext:Button runat="server" Text="Hide the first field">
<Listeners>
<Click Handler="App.TextField1.hide();" />
</Listeners>
</ext:Button>

<ext:Button runat="server" Text="Show the first field">
<Listeners>
<Click Handler="App.TextField1.show();" />
</Listeners>
</ext:Button>
</body>
</html>


Changing it to visible="false" instead of hidden="true" causes other issues.

Here are described the difference between these options.
http://forums.ext.net/showthread.php?13114&p=54033&viewfull=1#post54033

cwolcott
Oct 01, 2012, 1:26 PM
I made a minor modification to the onHide and onShow functions to allow for a field that has not been validated yet to not display an error after it is hidden and shown again. I did this my holding onto the field.hasActiveError() in the onHide funtion and during the onShow function only validate if the field originally had an active error. Seems to work fine.


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

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

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var onHide = function (field) {
field.originalHasActiveError = field.hasActiveError();
field.originalGetErrors = field.getErrors;
field.getErrors = function () { return []; };
field.validate();
};

var onShow = function (field) {
field.getErrors = field.originalGetErrors;
if (field.originalHasActiveError)
field.validate();
delete field.originalHasActiveError;
delete field.originalGetErrors;
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FieldContainer
runat="server"
CombineErrors="true"
MsgTarget="Under"
Width="300"
Layout="HBoxLayout" >
<Items>
<ext:TextField ID="TextField1" runat="server" AllowBlank="false">
<Listeners>
<Hide Fn="onHide" />
<Show Fn="onShow" />
</Listeners>
</ext:TextField>
<ext:TextField runat="server" AllowBlank="false" />
</Items>
</ext:FieldContainer>

<ext:Button runat="server" Text="Hide the first field">
<Listeners>
<Click Handler="App.TextField1.hide();" />
</Listeners>
</ext:Button>

<ext:Button runat="server" Text="Show the first field">
<Listeners>
<Click Handler="App.TextField1.show();" />
</Listeners>
</ext:Button>
</body>
</html>

Daniil
Oct 01, 2012, 1:28 PM
Thank you for sharing a solution for your case!

cwolcott
Oct 01, 2012, 2:12 PM
One final change needs to be made incase the field starts out as a hidden field. On the onShow function I need to test if the field.originalGetErrors is not undefined before assigning back to getErrors.


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

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

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var onHide = function (field) {
field.originalHasActiveError = field.hasActiveError();
field.originalGetErrors = field.getErrors;
field.getErrors = function () { return []; };
field.validate();
};

var onShow = function (field) {
if (!(field.originalGetErrors===undefined))
field.getErrors = field.originalGetErrors;
if (field.originalHasActiveError)
field.validate();
delete field.originalHasActiveError;
delete field.originalGetErrors;
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FieldContainer
runat="server"
CombineErrors="true"
MsgTarget="Under"
Width="300"
Layout="HBoxLayout" >
<Items>
<ext:TextField ID="TextField1" runat="server" AllowBlank="false">
<Listeners>
<Hide Fn="onHide" />
<Show Fn="onShow" />
</Listeners>
</ext:TextField>
<ext:TextField runat="server" AllowBlank="false" />
</Items>
</ext:FieldContainer>

<ext:Button runat="server" Text="Hide the first field">
<Listeners>
<Click Handler="App.TextField1.hide();" />
</Listeners>
</ext:Button>

<ext:Button runat="server" Text="Show the first field">
<Listeners>
<Click Handler="App.TextField1.show();" />
</Listeners>
</ext:Button>
</body>
</html>

Daniil
Oct 01, 2012, 7:47 PM
Thank you for sharing again!