Shahariar Fahim (Customer) asked a question.

How to correctly define a Choices field in viewmetadata.json for a dynamic module content list widget?

I'm working with Sitefinity CMS and trying to understand how to correctly define a Choices field in the

ViewMetaData.json

file for a dynamic module.

 

 

{

 "fieldTitle": "InputVoltage",

 "fieldType": "Choices"

}

 

But getting an error

 

"No field Match available. Choose another template."

 

Can anyone help me?? What to do??

 

imageimageimageThis is a radio button.

 

Is there anyone who can help me out of this??

 


  • Sabrie Nedzhip (Enso DX)

    Hi @Shahariar Fahim (Customer)​ ,

     

    The Choices field type is not yet supported for the field mappings.

    But you can still show the value of the choice field on the frontend in the view. The field mapping just let's you reuse the widget template for other content types and dynamically select from the widget edit view which content type properties for which mapped fields to use.

     

    Check this Sitefinity KB article for a sample on how to show a content item choice field value on the frontend: https://community.progress.com/s/article/renderer-display-choice-field-on-frontend

     

    Another option would be to sample from the Sitefinity github sample project:

     

    https://github.com/Sitefinity/sitefinity-aspnetcore-mvc-samples/blob/e4d38881c0270ca249244978c1b880bfe6701593/src/all-fields/Views/Shared/Fields/Choices.cshtml

     

    Here is what I tried:

     

    1. @using Progress.Sitefinity.AspNetCore.Mvc.Rendering;
    2. @using Progress.Sitefinity.RestSdk.Dto;
    3. @using Progress.Sitefinity.RestSdk;
    4.  
    5. @model Progress.Sitefinity.AspNetCore.Widgets.Models.ContentList.ContentListViewModel
    6.  
    7. @functions {
    8. enum InputVoltage
    9. {
    10. AC = 1,
    11. DC = 2,
    12. }
    13. }
    14.  
    15.  
    16. @foreach (var item in Model.Items)
    17. {
    18. var selectedSingleChoice = item.GetValue<InputVoltage>("InputVoltage");
    19. <div>
    20. <h3>
    21. <span>@Html.HtmlSanitize(item.GetValue<string>("Title"))</span>
    22. </h3>
    23. <div>@selectedSingleChoice</div>
    24. </div>
    25. }

     

    In the backend I create my content item and select the choice

     

    image 

    And On the frontend I see the selected value:

     

    image 

    And this is the type of the field in the module builder:

     

    image 

    You can choose what works best for you.

     

    Regards,

    Sabrie

     

    Selected as Best