Module Builder backend "Choice" Field

Posted by Community Admin on 04-Aug-2018 19:09

Module Builder backend "Choice" Field

All Replies

Posted by Community Admin on 23-Mar-2012 00:00

This field is broken on the backend

1) The screen where you choose which columns are in the list is showing description not title
2) So dragging that into the grid results in an insane length column header
3) When items are imported (using the code snippit) but not "Published" they have "Option" appened to their type name oddly.  We imported them unpublished so the content editor could go though 1 by 1 and categorize and publish...so she knows she hasn't done something yet by its current published state.
4) So reading #3, we can't filter on UnPublished

Posted by Community Admin on 27-Mar-2012 00:00

Hi Steve,

Thank you for contacting us.

About your first question the column names are the same as the labels for your fields. Choices fields have got only labels that could be longer because they might be questions or sentences. However your issue has a very simple workaround. What you need to do is to navigate to Administration -> Settings -> Advanced -> ContentView -> Controls -> YourCustomContentType -> Views -> ContentTypeBackendList -> View Modules -> Grid -> Columns -> YourColumnName -> Change "HeaderText" property the way you want it -> Save. You might need to recycle your app pool or restart your server.

As I see from your screenshot you haven't assigned any status to your content items and that's why you can't filter them on "UnPublished". Here is how you should set your items as unpublished:

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type sampleContentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.SampleModule.SampleContent");
DynamicContent sampleContentItem = dynamicModuleManager.CreateDataItem(sampleContentType);
  
// This is how values for the properties are set
sampleContentItem.SetValue("Title", "Some Title");
sampleContentItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
sampleContentItem.SetValue("PublicationDate", DateTime.Now);
// Set the selected value
sampleContentItem.SetValue("Choice", new string[] "First Choice", "Second Choice" );
 
//Setting the URL name
sampleContentItem.UrlName = "some-title";
  
dynamicModuleManager.Lifecycle.Publish(sampleContentItem);
  
dynamicModuleManager.SaveChanges();
  
//Saving the item as published
WorkflowManager.MessageWorkflow(sampleContentItem.Id, sampleContentType, null, "Publish", false, new Dictionary<string, string>());
  
//Saving the item as unpublished
WorkflowManager.MessageWorkflow(sampleContentItem.Id, sampleContentType, null, "Unpublish", false, new Dictionary<string, string>());
  
//Filtering items with status "Unpublished"
var items = dynamicModuleManager.GetDataItems(sampleContentType).Where(i => i.ApprovalWorkflowState == "Unpublished");

However as you can see saving item as unpublished requires to save your item first as published. You can avoid that if you prefer to save your new items as draft. Here is a code snippet how to do that:

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type sampleContentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.SampleModule.SampleContent");
            DynamicContent sampleContentItem = dynamicModuleManager.CreateDataItem(sampleContentType);
 
            // This is how values for the properties are set
            sampleContentItem.SetValue("Title", "Some Title");
            sampleContentItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
            sampleContentItem.SetValue("PublicationDate", DateTime.Now);
            // Set the selected value
            sampleContentItem.SetValue("Choice", new string[] "First Choice", "Second Choice" );
 
            //Setting the URL name
            sampleContentItem.UrlName = "some-title";
 
            //This will set that the item is saved as draft
            sampleContentItem.ApprovalWorkflowState = "Draft";
 
            dynamicModuleManager.SaveChanges();
 
            //Filtering items with status "Draft"
            var items = dynamicModuleManager.GetDataItems(sampleContentType).Where(i => i.ApprovalWorkflowState == "Draft");

As for the "option" that is added to your titles I have no idea where it comes from, neither I could reproduce it. Choices fields should be set as shown in the code reference:

sampleContentItem.SetValue("Choice", new string[] "First Choice", "Second Choice" );

But if you still have this problem more information and steps to reproduce this problem will be appreciated. 

Kind regards,
Stoimen Stoimenov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed