Custom PropertyData, with SelectionFactory issues

Vote:
 

Hi,
I have created a custom propertydata to hold a set of variables to be picked within a dropdown on a block.

This in it self was more difficult than i beileive it has a right to be - which means i probably did it wrong.
However, my issue is now that while it works, the dropdown can not tell what is already selected.

When i publish the block, the dropdown goes blank, but the model has the correct information.

I have tried to make sure to override Equals(), as i expected that would be used to find the proper selection, this is however not hit.

Does anyone know what is used within episerver to find the correct selection of a dropdown on a model, or knows how to manually set it at load?

#253126
Apr 13, 2021 7:05
Vote:
 

Hi,

Can you please provide the code snippet here.

One more thing please try to cast the values of your SelectionFactory into a string if it is of another type.

var selectableCategories = GetCategoriesWithChildren(categories,str, strings, list)
                .Select((x, i) => new SelectItem
                {
                    Text = strings[i],
                    Value = x.ID.ToString()
                });
#253127
Apr 13, 2021 7:32
Vote:
 

I have this in the selection factory;

public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var selectList = new List<ISelectItem>();
            foreach (var colorTheme in colorThemes)
            {
                selectList.Add(new SelectItem() { Text = colorTheme.Name, Value = colorTheme });
            }
            return selectList;
        }

It is used on the model as;

        [Display(
            Name = "Color Theme",
            Description = "Select the color theme to be used on the banner",
            GroupName = TabNames.Content,
            Order = 4)]
        [Required]
        [CultureSpecific]
        [SelectOne(SelectionFactoryType = typeof(ColorThemeSelectionFactory))]
        [BackingType(typeof(PropertyColorTheme))]
        public virtual ColorTheme ColorTheme { get; set; }

With the ColorTheme class, that holds a few different fields, and the backing type of PropertyColorTheme that extends PropertyData
It saves internally using the propertyDataType.String, using custom parser that just takes the values of the ColorTheme as a comma seperated string

#253130
Apr 13, 2021 7:37
Vote:
 

Include value string?

#253353
Apr 16, 2021 10:49
* 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.