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;
}
}
}