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!

Is there a way to choose a default value for a selection field of a form?

Vote:
 

I have a dropdown field on a form that is data driven by a selection feed. Is there a way to choose what the default value of the dropdown will be when it loads?

#206072
Aug 01, 2019 20:40
Vote:
 

Are you using the Epi Forms add-on? If so, which version?

#206073
Aug 01, 2019 23:04
Vote:
 

Yes, latest version 4.25

#206075
Aug 01, 2019 23:33
Vote:
 

Have you read Form element types, which explains how to work with the two types of dropdowns: "Selection" and "Multiple or Single Choice" ?  The Choices fields have a Checked by default property.

#206104
Edited, Aug 02, 2019 14:37
Vote:
 
#206112
Edited, Aug 02, 2019 16:19
Vote:
 

Both of those links are broken. The "checked by default" property is only available if you manually enter the choices. If you choose a selection feed there is no way to choose the default value. Was hoping you guys had a workaround.

#206118
Aug 02, 2019 16:58
Vote:
 

Hi Jason,

Have you checked the link that I provided? It is the same link that Bob mentioned in his comment.

#206119
Aug 02, 2019 17:01
Vote:
 

Yes I did, thanks. It only describes how to use the selection field for manual input choices. There is no mention of how to choose a default when you use a selection feed to fill the choices.

#206120
Aug 02, 2019 17:12
Vote:
 

Anyone have any suggestion how to do this? Surely I can't be the only one who has had this requirement for dynamic sources.

#206373
Aug 16, 2019 16:35
Vote:
 

After reading Kenny's post I realized the view of a SelectionElementBlock calls GetDefaultValue and GetDefaultSelectedString. You should be able to create a custom form element that inherits SelectionElementBlock and override those two methods to whatever you'd like.

Dummy feed

[ServiceConfiguration(ServiceType = typeof(IFeed))]
public class CustomFeed : IFeed, IUIEntityInEditView {

public IEnumerable<IFeedItem> LoadItems(){
var feedItems = new List<IFeedItem>();

feedItems.Add(new FeedItem { Key = "Custom data 1", Value = "1" });
feedItems.Add(new FeedItem { Key = "Custom data 2", Value = "2" });
feedItems.Add(new FeedItem { Key = "Custom data 3", Value = "3" });

return feedItems;
}

Feed Provider
public class FeedProvider : IFeedProvider{
public IEnumerable<IFeed> GetFeeds(){
return ServiceLocator.Current.GetAllInstances<IFeed>();}}
Custom form element with overriden GetDefaultValue.
public class DefaultValueSelectionBlock : SelectionElementBlock{
public override string GetDefaultValue(){
return "3";}}

Sending the default value of "3" will set the FeedItem with key "Custom data 3" as default when the dropdown is rendered.

#206391
Edited, Aug 19, 2019 16:17
* 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.