I tested with both CMS 11 and 12 and both have same behavior as you described. Without [Required] it works fine with empty string. With [Required] the best I could do is use a space character but as you say this can cause cascading issues. This must be because with empty string or null the row is completely removed from the tblContentProperty table to save space and that causes [Required] check to trigger. So it'd need internal code change to read the parameter to allow empty strings.
using EPiServer.Shell.ObjectEditing;
using System.Collections.Generic;
namespace AlloyTraining.Business.SelectionFactories
{
public class ThemeSelectionFactory : ISelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
return new List<SelectItem>
{
new SelectItem { Value = " ", Text = "None" },
new SelectItem { Value = "theme1", Text = "Orange" },
new SelectItem { Value = "theme2", Text = "Purple" },
new SelectItem { Value = "theme3", Text = "Green" }
};
}
}
}
I have a required property like so (notice how empty strings are allowed):
The selection factory includes both a null option, as well as an empty string option:
The idea is to force the user to explicitly select an option when creating content, but the user may opt to explicitly set the value to an empty string.
However, if the user selects the "Default" option, validation appears to still treat it like null (both properties below use the same pattern):
Of course we can change the "Default" option to have a non-empty value, but that would require refactoring of other parts - and I still think this behavior is odd?