Upgrading custom field type in Umbraco Forms (v10 ...
# help-with-umbraco
s
I need to update the code for a custom field type in Umbraco forms, but I'm having trouble with the settings for the field type. The existing values aren't showing up on the forms where the field is used. Should the pre-values be added in a different way on v13? The settings were added to the v10 version like this:
Copy code
c#
public class CountrySelect : FieldType
{
  private static readonly List<Setting> SettingsList = new List<Setting>
  {
    new KeyModeSettingAttribute("Select how value will be submitted")
  };

  public CountrySelect()
  {
    // ...
    // Field is defined here (Id (guid), FieldTypeViewName...
    // ...
  }
  public override Dictionary<string, Setting> Settings() => SettingsList.ToDictionary(l => l.Alias, l => l);
}
The
KeyModeSettingAttribute
looked like this:
Copy code
c#
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class KeyModeSettingAttribute : Setting
{
    public const string FieldAlias = "keyMode";

    private static readonly Dictionary<string, KeyMode> PrevaluesList = new Dictionary<string, KeyMode>
    {
        { "key", KeyMode.Key },
        { "title", KeyMode.Title },
        { "english title", KeyMode.EnglishTitle }
    };

    public KeyModeSettingAttribute(string description)
        : base("Key Mode")
    {
        this.Description = description;
        this.View = "dropdownlist";
        this.Alias = FieldAlias;
        this.PreValues = string.Join(",", PrevaluesList.Keys);
    }
}
In v13 I have tried to update the code to this:
Copy code
c#
public class CountrySelect : FieldType
{
  public CountrySelect()
  {
    // ...
    // Field is defined here (Id (guid), FieldTypeViewName...
    // ...
  }
  
  [Setting("Key Mode", Alias = "keyMode", Description = "Select how value will be submitted", View = "dropdownlist", PreValues = "key,title,english title")]
  public string KeyMode { get; set; }
}
I have created a repo where it is easy to replicate the issue - https://github.com/mastrup/FormsUpgradeTest Also, I am in contact with Umbraco Support about it.
2 Views