Help with the form field for a custom form

So when adding a radio button we a dropdown for Display Layout:

We made a new custom radio that appears as buttons and we would like this same display layout dropdown. Despite everything I tried to get a dropdown I can’t get it to work. I feel the answer is in this document but I can’t figure out what it would be.

While I really would like to match the look and use a dropdown, I got it to at least display with a with a toggle, but then it won’t submit. From what it sounds it was some validation issue even though it isn’t showing any errors, it just does nothing when I click submit.

Can someone tell me what I need to make a dropdown work for this or at least where I would look in my files to find out what I need to use? Here is my code below for the toggle (that doesn’t submit). I assume on the CSHTML file it would be the same logic for the radio.

Any help is appreciated!

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Umbraco.Forms.Core;
using Umbraco.Forms.Core.Attributes;
using Umbraco.Forms.Core.Enums;
using Umbraco.Forms.Core.Models;
using Umbraco.Forms.Core.Services;

namespace BiberkUmbraco.Themes
{
    public class ButtonListField : FieldType
    {
        public ButtonListField()
        {
            Id = new Guid("f9c0b4b6-bfcf-4898-b123-9d334b509d11");
            Name = "Button List";
            Description = "Displays a set of buttons instead of radio options.";
            Icon = "icon-radio";
            DataType = FieldDataType.String;
            SortOrder = 5;
            SupportsPreValues = true;
            FieldTypeViewName = "FieldType.ButtonList.cshtml";
        }

        [Setting("Horizontal Layout",
            Description = "Check this box to display buttons horizontally instead of vertically.",
            View = "Umb.PropertyEditorUi.Toggle")]
        public bool HorizontalLayout { get; set; } = false;

        public override List<Exception> ValidateSettings()
        {
            return new List<Exception>();
        }

        public override IEnumerable<string> ValidateField(
            Form form,
            Field field,
            IEnumerable<object> postedValues,
            HttpContext context,
            IPlaceholderParsingService placeholderParsingService,
            IFieldTypeStorage fieldTypeStorage)
        {
            var returnStrings = new List<string>();

            if (field.Mandatory && (!postedValues.Any() || postedValues.All(x => string.IsNullOrWhiteSpace(x?.ToString()))))
            {
                returnStrings.Add(field.RequiredErrorMessage);
            }

            return returnStrings;
        }
    }
}

Hi!

Just so that I understand your problem,

Do you see the toggle in the UI and the issue is that the value is not persisted?

Could it be (guessing here) that the setting needs to be a string and not a bool?

Thank you so much for following up! Reading back that was incredibly unclear, that tends to happen when I am responding in peak frustration. In the future I should send my replies through chatGTP or something to make sure it’s readable.

We set aside the issue for now, but basically we needed to see the option for choosing horizontal/vertical in our custom field type that was in the Radio Button List (single choice). We didn’t know where the code was to make the single choice option happen and were just hoping to copy that.

My main issue was I was having trouble figuring out what the dropdown is called in Umbraco 15 forms. I could not get a dropdown to appear, I could have it be a text input that accepts only “vertical” or “horizontal”. I also got a radio to work, but then it was apparently haven’t some hidden validation issues on input

I believe I tried to treat it like text and not a bool but when I get back to it I’ll try that again, thank you very much!