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",
}
Hi,
SetDefaultValues vil not work for me. I want to check and set the value every time the property is rendered in edit mode.
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;
}
Can I set InitialValue to many values? I have a CheckBoxList so I want to set more than one item as selected
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.
I tried that, but the values appended to InitialValue was ignored. Any other suggestions? :)
Hmm, off the top of my head none that doesnt involve dojo :) Sorry, I'll write here if I figure something out :)
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.
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?
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