November Happy Hour will be moved to Thursday December 5th.

Setting a ISelectItem as selected

Vote:
 

Hi,

I have made a EditorDescriptor that renders a CheckBoxList. Is it possible to set some of the ISelectItems returned by the ISelectionFactory as selected? I can only set Text and Value, but it would be nice to set some of the items as selected as well. Does anyone know if this is possible?

/Tore

#90996
Sep 23, 2014 15:47
Vote:
 

Hi,

Not sure if you can do this globally in your editor. But you can set the default value in your content type:

public override void SetDefaultValues(ContentType contentType)
{
    base.SetDefaultValues(contentType);

    YourProperty = "TheDefaultValue",
}
#91008
Sep 24, 2014 3:36
Vote:
 

Hi,

SetDefaultValues vil not work for me. I want to check and set the value every time the property is rendered in edit mode.

#91027
Sep 24, 2014 12:30
Vote:
 

The ExtendedMetadata object that is given as argument to the GetSelections-method in a selectionfactory has an InitialValue property you can use. such as this:

public IEnumerable GetSelections(ExtendedMetadata metadata)
        {
            var list = new List
            {
                new SelectItem {Text = "test", Value = "val1"},
                new SelectItem {Text = "test2", Value = "val2"}
            };

            metadata.InitialValue = "val2";

            return list;
        }
#91028
Sep 24, 2014 13:00
Vote:
 

Can I set InitialValue to many values? I have a CheckBoxList so I want to set more than one item as selected

#91031
Sep 24, 2014 13:18
Vote:
 

I havent tested it personally, but since EPiServer internally stores the property value as a comma separated string, I imagine you could just set the InitialValue as "val1,val2,val3" etc.

#91033
Sep 24, 2014 13:30
Vote:
 

I tried that, but the values appended to InitialValue was ignored. Any other suggestions? :)

#91035
Sep 24, 2014 13:42
Vote:
 

Hmm, off the top of my head none that doesnt involve dojo :) Sorry, I'll write here if I figure something out :)

#91036
Sep 24, 2014 13:46
Vote:
 

When creating the editor interface, a form is created totally unaware of the values. Then it's then bound to the values of the object it should edit. This means that there is no good way or getting an editor in a shape that's different then the actual value of the object, unless you somehow make a custom editor. In the old UI, there was an event to be able to modify the object that was used for editing, for instance creating check boxes that were always in a given state, regardless of the actual backing object (Tweaking the default value of "Mark Page as Changed" is a perfect example of this). This is not possible in the new UI since the object returned are used for the entire UI, not only the form.

As Johan already pointed out, you can set the default values to get this behavior when creating new items. But there is currently no supported way of getting this behavior when editing existing objects except of building your own custom editor. If you really need to impement this, the best way is probably inherriting from the built in editor for check boxes (CheckBoxListEditor) and overriding the _setValueAttr method, copy the code for the base class and tweak this.

#91080
Sep 25, 2014 13:47
Vote:
 

Hi Linus,

Thanks for your answer! I will try to create a new editor that inherits from the CheckBoxListEditor. If I modify the metadata.InitialValue in my SelectionFactory, will these be passed to the new editor? If not, how will I be able to pass the altered values to my new editor?

#91082
Sep 25, 2014 14:08
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.