Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pinal Bhatt 298 posts 389 karma points
    Mar 16, 2011 @ 03:04
    Pinal Bhatt
    0

    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?

     

  • Sebastiaan Janssen 4843 posts 14347 karma points MVP admin hq
    Mar 16, 2011 @ 09:21
    Sebastiaan Janssen
    1

    How about @if(Mode.defaultTab.ToString != "" && Model.defaultTab > 0) { .. }

  • Pinal Bhatt 298 posts 389 karma points
    Mar 16, 2011 @ 11:07
    Pinal Bhatt
    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)

     

  • Sebastiaan Janssen 4843 posts 14347 karma points MVP admin hq
    Mar 16, 2011 @ 11:49
    Sebastiaan Janssen
    1

    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. :)

  • Pinal Bhatt 298 posts 389 karma points
    Mar 17, 2011 @ 11:05
    Pinal Bhatt
    0

    Thanks Sebastiaan. I will try by applying validation to that field.

    and will raise an issue for this in codeplex.

     

  • Markus 33 posts 58 karma points
    Apr 09, 2011 @ 15:45
    Markus
    0

    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.

  • Nicolas 26 posts 46 karma points
    Feb 08, 2012 @ 22:03
    Nicolas
    0

    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

  • Jeroen Breuer 4860 posts 12121 karma points MVP 3x admin c-trib
    Feb 09, 2012 @ 06:46
    Jeroen Breuer
    0

    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

  • firepol 125 posts 173 karma points
    Dec 11, 2012 @ 14:31
    firepol
    0

    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...

  • Sebastiaan Janssen 4843 posts 14347 karma points MVP admin hq
    Dec 11, 2012 @ 14:34
    Sebastiaan Janssen
    0

    This was fixed for 4.10.0 - http://issues.umbraco.org/issue/U4-366

     

  • firepol 125 posts 173 karma points
    Dec 11, 2012 @ 14:52
    firepol
    0

    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...

  • firepol 125 posts 173 karma points
    Dec 11, 2012 @ 15:57
    firepol
    0

    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

  • Pinal Bhatt 298 posts 389 karma points
    Dec 18, 2012 @ 20:07
    Pinal Bhatt
    0

    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"

    @CurrentPage.Descendants("eBook").First().FeatureId.GetType().ToString()  
    // Output: System.String

     

    Thanks & Regards,
    Pinal Bhatt 

Please Sign in or register to post replies

Write your reply to:

Draft