Copied to clipboard

Flag this post as spam?

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


  • Lennart Stoop 304 posts 842 karma points
    Apr 23, 2011 @ 17:28
    Lennart Stoop
    0

    Default data editor setting for a checkbox

    Hi all,

    I have a custom data editor which implements the IUserControlWrapper and uses attributes for its data editor settings. Setting default values for textboxes works fine:

            [DataEditorSetting("TextBoxSetting", defaultValue = 5)]
    public string TextBoxSetting { get; set; }

    When I want to use a checkbox however, the default value is not picked up properly:

            [DataEditorSetting("CheckBoxSetting", defaultValue = "True",
                type = typeof(umbraco.editorControls.SettingControls.CheckBox))]
            public string CheckBoxSetting { get; set; }

    I have also tried setting the default value as a boolean, but this does not work either.

    Has anyone else had this issue before ?

    Using Umbraco 4.7.0 / .NET 4

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Apr 26, 2011 @ 08:23
    Sebastiaan Janssen
    0

    Have you tried using 1 as a value? Umbraco stores true/false as 1 and 0.

  • Lennart Stoop 304 posts 842 karma points
    Apr 26, 2011 @ 20:53
    Lennart Stoop
    0

    Hi @cultiv

    No luck using 1 either, tried both an integer and a string.

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Apr 27, 2011 @ 16:45
    Sebastiaan Janssen
    0

    That's a shame, I don't know the anwer then. What I usually end up doing is negate the checkbox. So if the checkbox asks: "This page should have a blue border", then I turn it into: "This page should not have a blue border". This could be inconvenient in your situation though, but it's worth considering.

  • Lennart Stoop 304 posts 842 karma points
    Apr 27, 2011 @ 19:38
    Lennart Stoop
    0

    I guess that could work but it's a tricky workaround. For now its not a showstopper though and its OK having the checkboxes unchecked by default.

    I'll have a look what's going on behind the scenes and see if there's a proper solution for it, it does seem to work when using prevalues so I guess that's an option too.

    Thanks though!

  • Bo Kingo Damgaard 157 posts 456 karma points
    May 22, 2012 @ 12:08
    Bo Kingo Damgaard
    0

    I know this an old thread, but I just ran into the same issue in 4.7.1.1, and it's a bug Umbraco. The values from the properties used for settings are stored as strings, and when they are loaded the are not properly converted/casted to the proper type. Therefore a boolean is always false, because it's stored in as "True" instead of true.

    Solution:
    In umbraco.editorControls.userControlWrapper.usercontrolDataEditor, I've replaced line 77:

    oControl.GetType().InvokeMember(setting.Key, System.Reflection.BindingFlags.SetProperty, null, oControl, new object[] { setting.Value });
    with
    var prop = oControl.GetType().GetProperty(setting.Key);
    var value = Convert.ChangeType(setting.Value, prop.PropertyType);
    oControl.GetType().InvokeMember(setting.Key, System.Reflection.BindingFlags.SetProperty, null, oControl, new object[] { value });

    Another workaround is to user a string property as setting and then have another bool property that gets set accordingly - like this:

    [DataEditorSetting("Is this field mandatory in the App", type = typeof(umbraco.editorControls.SettingControls.CheckBox))]
    public string IsMandatoryString { get; set; }
    bool IsMandatory {
         get {
             return IsMandatoryString.ToLower() == "true";
         }
         set {
             IsMandatoryString = value.ToString();
         }
    }

    I'll submit the bug to codeplex

  • Bo Kingo Damgaard 157 posts 456 karma points
    May 22, 2012 @ 12:13
Please Sign in or register to post replies

Write your reply to:

Draft