Checkbox loses checked value in view, Edit mode

Vote:
 

Hi,

I have created a group of checkboxes wich the editors can check if wanted. My problem is that when a editor checkes for example:

  • check box A and check box B
  • publish it
  • goes back to the page in Edit mode. Now the check boxes lookes unchecked but the values are correct in the db and the application returns the right values according to the checked values. It just lookes unchecked in EpiServer Edit mode when in fact they are checked.

Does anyone know what I h ave missed or what I can do so that it in EPiServer shows the right status of the checkboxes?

I'm using the SelectMany attribute of EPiServer on my property holding the check boxes.

#147900
Apr 27, 2016 14:14
Vote:
 

http://stackoverflow.com/questions/32185447/how-do-you-support-selecting-multiple-enum-values-for-an-episerver-property

#147923
Apr 27, 2016 19:06
Vote:
 

I ran into this issue today, and my problem was also the underlying Value type of the SelectItem. It looks like the Value needs to be a string.

Given you have a property that is a SelectMany:

    [SelectMany(SelectionFactoryType = typeof(ChildPagesSelectionFactory))]
    public virtual string ChildPages { get; set; }

A common custom ISelectionFactory could be to return a list of child pages:

    public class ChildPagesSelectionFactory : ISelectionFactory
    {
        private Injected<IContentLoader> _contentLoader;
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var contents = _contentLoader.Service.GetChildren<IContent>(ContentReference.StartPage);
            return contents.Select(content => new SelectItem { Text = content.Name, Value = content.ContentLink.ID });
        }
    }

This code would cause the issue you described, since the Value is of type int.

To solve this, cast the Value to a string:

    public class ChildPagesSelectionFactory : ISelectionFactory
    {
        private Injected<IContentLoader> _contentLoader;
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var contents = _contentLoader.Service.GetChildren<IContent>(ContentReference.StartPage);
            return contents.Select(content => new SelectItem { Text = content.Name, Value = content.ContentLink.ID.ToString() });
        }
    }

This issue was reproduced and tested in Alloy MVC running CMS 9.8.3.

This is not an issue if you are using a SelectOne property.

I have a support ticket opened for this. Hopefully it'll be marked as a bug and fixed.

#148214
May 05, 2016 23:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.