PDA

View Full Version : [CLOSED] Ext:Hidden value



cwolcott
Nov 05, 2014, 1:48 PM
What basic issue am I missing/overlooking in the example below? Perform the following:


Launch page and inspect App.SampleHidden.value (Undefined - GOOD)
Press the "DOIT" button and inspect App.SampleHidden.value ("true" - BAD, I was expecting a boolean and not a string;
Press the browsers refresh button and inspect App.SampleHidden.value (true - GOOD)


When the hidden value is set I was hoping it would always be a Boolean.



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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (X.IsAjaxRequest) return;
SetHidden();
}

protected void Doit(object sender, DirectEventArgs e)
{
Session["ABC"] = "Set";
SetHidden();
}

private void SetHidden()
{
if (Session["ABC"] == null) return;
SampleHidden.SetValue(Convert.ToBoolean("true"));
}
</script>

<head runat="server">
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Panel runat="server">
<Bin>
<ext:Hidden ID="SampleHidden" runat="server" ClientIDMode="Static" />
</Bin>
<Items>
<ext:Button runat="server" Text="DOIT" OnDirectClick="Doit" />
</Items>
</ext:Panel>
</form>
</body>
</html>

Daniil
Nov 05, 2014, 2:26 PM
Hi Chris,

Interesting.

I can suggest this solution.

Ext.define("MyOverrides", {
override: "Ext.form.field.Hidden",

valueToRaw: function(value) {
return Ext.value(value, '');
//return '' + Ext.value(value, ''); // The original function's body
}
});

cwolcott
Nov 05, 2014, 2:57 PM
That didn't fix it. It seems that a call through a direct event is causing it to be a string again, vs the refresh browser (ie. Page_Load) is allowing it to be a Boolean.


Press the browsers refresh button and inspect App.SampleHidden.value (true - GOOD)
Now press the DOIT button again and we are back to a string value instead of a boolean value.

Daniil
Nov 05, 2014, 3:31 PM
The override helps me - I see a boolean true value after click on "DOIT".

Please provide a test case with override applied.

cwolcott
Nov 05, 2014, 3:49 PM
Here is the integrated code.

I have tested this in IE9, IE8 and Chrome 31 using Ext.NET Rev 5720.

Whenever I hit the DOIT button and inspect App.SampleHidden.value I get the string value "true", while after I press the browsers refresh button and inspect App.SampleHidden.value I get the Boolean value true.



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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (X.IsAjaxRequest) return;
SetHidden();
}

protected void Doit(object sender, DirectEventArgs e)
{
Session["ABC"] = "Set";
SetHidden();
}

private void SetHidden()
{
if (Session["ABC"] == null) return;
SampleHidden.SetValue(Convert.ToBoolean("true"));
}
</script>

<head runat="server">
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
Ext.form.field.Hidden.override({

valueToRaw: function (value) {
return Ext.value(value, '');
//return '' + Ext.value(value, ''); // The original function's body
}

});
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Panel runat="server">
<Bin>
</Bin>
<Items>
<ext:Hidden ID="SampleHidden" runat="server" ClientIDMode="Static" />
<ext:Button runat="server" Text="DOIT" OnDirectClick="Doit" />
</Items>
</ext:Panel>
</form>
</body>
</html>

cwolcott
Nov 05, 2014, 5:23 PM
Ok. This is working just fine in my actual project, not sure why it isn't working with the code shown above.

Was the original function's body changed to --> return '' + Ext.value(value, ''); from something else?

Is this an actual bug and potentially fixed in the future or do I need to always have this override.

Daniil
Nov 05, 2014, 5:23 PM
I don't know how I tested:) Sorry.

Well, I tried to suggest you a workaround (unsuccessfully), but the problem is a bit more complicated.

It turns out that a Hidden is not supposed to deal with non-strings at all.

Yes, hidden.value show a boolean true after page refresh, but you should use .getValue() method. It returns a string still.

So, please deal with a string or use a Hidden's Tag.

SampleHidden.Tag = Convert.ToBoolean("true");

The Tag property is not converted to string, the type should persist.

cwolcott
Nov 05, 2014, 7:13 PM
Got it. If have changed my code to use .tag on the clientside so the javascript looks cleaner.

Please close the thread.