Try our conversational search powered by Generative AI!

Is it possible to load custom setting values for PropertyCheckBoxList type?

Vote:
 

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

#71004
May 07, 2013 10:18
Vote:
 

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,

#71008
May 07, 2013 10:56
Vote:
 

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,

#71009
May 07, 2013 10:56
Vote:
 

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:

http://joelabrahamsson.com/enum-properties-with-episerver/

#71016
May 07, 2013 11:49
Vote:
 

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

#71017
May 07, 2013 12:10
Vote:
 

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.

#71019
May 07, 2013 12:32
Vote:
 

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] };
            }
        }

#71023
May 07, 2013 13:23
Vote:
 

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.

#71026
May 07, 2013 13:44
Vote:
 

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.

#71028
May 07, 2013 13:50
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.