Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
what i would like to achieve is when the pagetype created in the first time, i want to load some custom settings in propertychecklist property,
what i would like to achieve is when the pagetype created in the first time, i want to load some custom settings in propertychecklist property,
PropertyCheckBoxList is kind of obsolete when working in EPiServer 7. Try using a selectionFactory together with the built in checkboxlisteditor instead as described in Joel's blog:
Hey Linus
Thanks for your quick response. EditorDescriptor is the first option came to my mind when I planned to implement this feature. However, our client wants to be able to add the values dynamically, they used to use custom settings to add more options in the PropertyCheckBoxList property. If I choose the EditorDescriptor option, I have to manually create a custom plugin and implement the CRUD to maintain the datasource which makes the client feel annoying.
I would like you to give me an advice how can I make this value become dynamic?
Really appreciate for your help
Also this is just like a tagging functionality, I don't want to create another pagetype to maintain the tag list, it's inconvenient for the client.
Hi again!
I need to withdraw the statement that the PropertyCheckBoxList is obsolete. It still provides a value when you want to fetch property settings. It doesn't really take that much code to implement so you can create your own logic and implement default values. Basically you define an editor descriptor that defines a selection factory:
[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = "CheckBoxList")]
public class CheckBoxListEditorDescriptor : EditorDescriptor
{
public CheckBoxListEditorDescriptor()
{
SelectionFactoryType = typeof(YourCustomSelectionFactory);
ClientEditingClass = "epi-cms.contentediting.editors.CheckBoxListEditor";
}
}
And then you implement your own selection factory. Here is the code to fetch values from property settings:
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
PropertyData propertyData = metadata.Model as PropertyData;
if (propertyData == null)
{
yield break;
}
MultipleOptionsListSettings settings = (MultipleOptionsListSettings)propertyData.GetSetting(typeof(MultipleOptionsListSettings));
foreach (string key in settings.ListOptions.Keys)
{
string name = TranslateNameIfPossible(key);
yield return new SelectItem { Text = name, Value = settings.ListOptions[key] };
}
}
Again, thanks for your code snippet.
However, it still dosesn't answer one of my question. How can I programmatically add custom settings for this property when the pagetype was first created? As far as I see when I used this custom EditorDescriptor, the property type changed to String, I am not able to add custom settings values from UI anymore.
Check out the OnContentTypeSaved event on IContentTypeRepository. Check if you content type has any properties of the specified type with no property settings and assign default property settings if that is the case. I must warn you that you are in pretty deep water so you will need to spend some time to actually investigate and implement this.
Hi
I am having a page type contains a PropertyCheckBoxList property, if there is no value set up in custom setting section, the admin UI doesn't render anything.
Can someone tell me whether it is possible to achieve this?
my custom page looks like
public class blog : PageData{
[BackingType(typeof(PropertyCheckBoxList))]
public virtual string Tags{get;set;}
}
Thanks