Try our conversational search powered by Generative AI!

check boxes does not remember state

Vote:
 

Hi 

I have a page that gives content editors the ability to check some checkes boxes. However when they click on publish the checkboxes are cleared. 

The funny thing is that eventhough the checkboxes are cleared, somehow EPiServer remembers the choiches, making it possible for me to retrieve the value of the marked check boxes using the api. 

What can I do to have episerver remember the state of checkboxes. 

#147309
Apr 11, 2016 16:42
Vote:
 

The check boxes, are they Episerver properties? Can you share some code?

What version are you running on Episerver?

#147315
Apr 11, 2016 21:32
Vote:
 

Sorry for not supplying any code samples. I hoped it would be needed. 

Its EPiServer CMS 9 and its an EPiServer property.

Here is the code:

The model

        [UIHint(CustomUiHints.SubscriptionPageSelector)]
        public virtual string SubscriptionPages { get; set; }

The  C# code that creates the checkboxes

    [EditorDescriptorRegistration(TargetType = typeof(string), UIHint = CustomUiHints.SubscriptionPageSelector)]
    public class SubscriptionPageEditorDescriptor : EditorDescriptor
    {
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            SelectionFactoryType = typeof(SubscriptionPageSelectionFactory);
            ClientEditingClass = "epi-cms.contentediting.editors.CheckBoxListEditor";
            base.ModifyMetadata(metadata, attributes);
        }
    }

    public class SubscriptionPageSelectionFactory : ISelectionFactory
    {
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var subscriptionPages = new List<SelectItem>();
            var subscriptions = ...GetSubscriptions
            foreach (var sub in subscriptions)
            {
                subscriptionPages.Add(new SelectItem() { Value = sub.Value, Text = sub.Key });
            }
            return subscriptionPages;
        }
    }

The CustomUIHints files

public const string SubscriptionPageSelector = "SubscriptionPageSelector";

The code is runned inside a scheduledJob. 

The xml structure is as in the picture. (if the picture is not visible then go to this url: http://tinypic.com/r/5aj09k/9 )

There is a container page that has children each child has the checkboxes. 

xml tree

When retreving the values of the checkboxes the values are presented in a comma separated list, if the image is not visible, please refer to: http://postimg.org/image/phklg4dcn/

values

The information given above may be too much, in order to understand why the checkboxes arent preserving their state after publish. 

Note I have not created any controller og view for the model. Since the model will only be used to provide the checkbox list

#147326
Edited, Apr 12, 2016 9:36
Vote:
 

Try changing

subscriptionPages.Add(new SelectItem() { Value = sub.Value, Text = sub.Key });

to 

subscriptionPages.Add(new SelectItem() { Value = sub.Value.ToString(), Text = sub.Key });

#147331
Apr 12, 2016 10:13
Vote:
 

You're the man Daniel. 

That actually worked. 

Maybe you could throw in some few words about why that would do the trick. 

#147333
Apr 12, 2016 11:12
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.