In Umbraco 4.7 final release, I have a document type property "defaultTab" of type numeric as below:
Now in razor macro, @Model.defaultTab.GetType().ToString() behaves strange. If no value is provided to defaultTab, it retruns "System.String" and when any numeric value is passed its returns "System.Int32".
Is this the expected behavour or is this a bug?
What is a workaround for this? In razor code i need to have logic to check if defaultTab is > 0.
@if(Model.defaultTag > 0) {...}
Now if no value is passed to defaultTag, I get runtime error stating that '>' cannot be used with string type.
How to handle this issue in razor script in umbraco 4.7?
Well, I was trying to do this with .HasValue first but that threw an error for me, so I solved it this way. I do think that in this case, a datatype that only accepts ints, it should be safe to make it nullable. But in the datatype definition, you can also specify the datbase field to be date or nvarchar, so I don't know if the validation would change in that case.
Anyway, you should raise an issue for it, I think it should be looked at. :)
I also have the same problem, nearly one year after! And Sebastiaan's solution won't work, because if the numeric field is empty, it will return a string, which doesn't have a toString method (it is logic).
What version of Umbraco are you using? There are some differences on when a value is returned as a string or int. Think in 4.7.1.1 it should always return an int.
This is really bothering me... I have a numeric property for a document type. It's not set as mandatory. So I expect umbraco to let me save also an empty value, which is not the case.
Let's say I save a number "100". Then I come back I delete 100 and leave empty, click on "save and publish" the node will be saved with the old value, 100 in my case, instead of "" (empty). It's quite a big bug: if a user is fast to save and navigate away he will not see that the change was not taken.
I tried to use the regular expression to validate, it doesn't work. I'm considering to add some javascript validation before the user clicks on save...
I'm using 4.11.1 (after having upgraded fropm 4.10) and when I leave the numeric empty, the old value is saved. Doesn't seem fixed to me... I will check ona fresh 4.11.1 installation and let you know...
I just tested on a fresh umbraco 4.10.1 and 4.11.1 installation, the validation is not working properly and if a number is followed by a space and som text, the validation doesn't occur and the previous value (if any) is saved, without any error message displayed at the top.
Numeric type returning string when empty
Hi,
In Umbraco 4.7 final release, I have a document type property "defaultTab" of type numeric as below:
Now in razor macro, @Model.defaultTab.GetType().ToString() behaves strange. If no value is provided to defaultTab, it retruns "System.String" and when any numeric value is passed its returns "System.Int32".
Is this the expected behavour or is this a bug?
What is a workaround for this? In razor code i need to have logic to check if defaultTab is > 0.
@if(Model.defaultTag > 0) {...}
Now if no value is passed to defaultTag, I get runtime error stating that '>' cannot be used with string type.
How to handle this issue in razor script in umbraco 4.7?
How about @if(Mode.defaultTab.ToString != "" && Model.defaultTab > 0) { .. }
Thanks Sebastiaan. I had similar workaround, but still your suggestion is better.
BTW, Is this the expected behavour or is this a bug? Idealy I am expecting that datatype for "defaultTab" in this case should be int? (nullable Int32)
Well, I was trying to do this with .HasValue first but that threw an error for me, so I solved it this way. I do think that in this case, a datatype that only accepts ints, it should be safe to make it nullable. But in the datatype definition, you can also specify the datbase field to be date or nvarchar, so I don't know if the validation would change in that case.
Anyway, you should raise an issue for it, I think it should be looked at. :)
Thanks Sebastiaan. I will try by applying validation to that field.
and will raise an issue for this in codeplex.
I ran into the same problem. I was expecting null, Nullable int32 or the default value of int, but not a different type.
I couldn't find the issue on codeplex - could you please post the link so I can vote for it? Thanks.
Hello,
I also have the same problem, nearly one year after! And Sebastiaan's solution won't work, because if the numeric field is empty, it will return a string, which doesn't have a toString method (it is logic).
Is there an update to fix this?
Thanks
What version of Umbraco are you using? There are some differences on when a value is returned as a string or int. Think in 4.7.1.1 it should always return an int.
Jeroen
This is really bothering me... I have a numeric property for a document type. It's not set as mandatory. So I expect umbraco to let me save also an empty value, which is not the case.
Let's say I save a number "100". Then I come back I delete 100 and leave empty, click on "save and publish" the node will be saved with the old value, 100 in my case, instead of "" (empty). It's quite a big bug: if a user is fast to save and navigate away he will not see that the change was not taken.
I tried to use the regular expression to validate, it doesn't work. I'm considering to add some javascript validation before the user clicks on save...
This was fixed for 4.10.0 - http://issues.umbraco.org/issue/U4-366
I'm using 4.11.1 (after having upgraded fropm 4.10) and when I leave the numeric empty, the old value is saved. Doesn't seem fixed to me... I will check ona fresh 4.11.1 installation and let you know...
I just tested on a fresh umbraco 4.10.1 and 4.11.1 installation, the validation is not working properly and if a number is followed by a space and som text, the validation doesn't occur and the previous value (if any) is saved, without any error message displayed at the top.
Here I re-opened the bug: http://issues.umbraco.org/issue/U4-1314
Looks like in 4.11.1, numeric fields are exposed as strings.
My "FeatureId" field is defined as numeric and has valid numeric value still following statement outputs "System.String"
// Output: System.String
Thanks & Regards,
Pinal Bhatt
is working on a reply...