London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
Hi,
You can set the default value.
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
//Set values here
}
@Ravindra S. Rathore,
I think I have tried it and it partly works - on publish it passes further the default value, but the placeholder of selectbox is still empty
Hi all,
I found this topic here - https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2014/9/Setting-a-ISelectItem-as-selected/ - but none of the solutions solves my problem.
I have this property on a page, which uses custom Selection Factory.
And I want to set initial value and display it's placeholder (in admin view, under "All properties" view while creating new page) here in a select box. I do it like this:
// CustomSelectionFactory.cs: public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata) { List<SelectItem> result = new List<SelectItem>() { new SelectItem() { Text = "All", Value = null } }; List<CustomSelectItem> customSelectItems = new List<CustomSelectItem>(); switch (metadata.PropertyName) { case "DocumentCountry": customSelectItems = Api.GetCustomSelectItems(1).Result; break; case "DocumentLanguage": customSelectItems = Api.GetCustomSelectItems(2).Result; result.RemoveAll(x => x.Text == "All"); metadata.InitialValue = "1"; break; } foreach (CustomSelectItems customSelectItem in customSelectItems) { result.Add(new SelectItem() { Text = customSelectItem .Name, Value = customSelectItem .Id.ToString() }); } return result; }
// CustomPage.cs [Display(Name = "Document Country")] [SelectOne(SelectionFactoryType = typeof(CustomSelectionFactory))] public virtual string DocumentCountry { get; set; } [Display(Name = "Document Language")] [SelectOne(SelectionFactoryType = typeof(CustomSelectionFactory))] public virtual string DocumentLanguage { get; set; }
Help appreciated!