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:
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.
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.
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(); } }
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:
When I want to use a checkbox however, the default value is not picked up properly:
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
Have you tried using 1 as a value? Umbraco stores true/false as 1 and 0.
Hi @cultiv
No luck using 1 either, tried both an integer and a string.
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.
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!
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:
Another workaround is to user a string property as setting and then have another bool property that gets set accordingly - like this:
I'll submit the bug to codeplex
Codeplex issue: http://umbraco.codeplex.com/workitem/30821
is working on a reply...