How to define default values for Form Field Settings

Hi,
I’m trying to customise the existing FieldTypes (such as Textbox, Textarea, FileUpload etc.) so that I can define default values that are pre-filled when building the form for some of the settings properties. I’ve attempted this by using Adding A Field Type To Umbraco Forms | Umbraco Forms as a guide however I’ve not been successful.

For example, I’ve tried the following code in an attempt to have The ‘AutocompletAttribute’ property value pre-filled and defaulted to “on” for the Textarea field type:

public class Textarea : Umbraco.Forms.Core.Providers.FieldTypes.Textarea
{
    [Setting(
        "Show Label",
        Description = "Indicate whether the the field's label should be shown when rendering the form.",
        View = "checkbox",
        PreValues = "true",
        DisplayOrder = 30,
        IsHidden = true
    )]
    public override string ShowLabel { get; set; } = "True";

    [Setting(
        "Autocomplete attribute",
        Description = "Optionally enter a value for the autocomplete attribute.",
        PreValues = "on",
        View = "TextField",
        DisplayOrder = 40
    )]
    public override string AutocompleteAttribute { get; set; } = "on";


    [Setting(
        "Number Of Rows",
        Description = "Enter the number of rows displayed for entry",
        View = "NumericField",
        PreValues = "5",
        DisplayOrder = 50
    )]
    public override string NumberOfRows { get; set; } = "5";

    public override bool SupportsRegex => false;
}

In this situation, I’m trying to auto-populate the highlighted area with “on” when the Question modal is first loaded:

Lastly, I’ve tried to locate a Forms specific Notification that would allow for the pre-population of these values like the SendingContentNotification (EditorModel Notifications | Umbraco CMS) that allows for pre-population of values in the Content section of Umbraco. However, I have not been able to find anything in the documentation or Umbraco.Forms namespace.

Unfortunately, all of the above have failed to produce the results I am after. Does anyone know how I can achieve this?

Hey @bnewton-kleenheat :waving_hand:

I agree, something not quite right here; I wasn’t able to get defaults working on this at all (either on overwritten fields, or new fields) - I’m using Forms v13.4.2.

Here’s what I’m seeing from my side, I would have expected the name of the “Default Value” to show “Default OOTB Value” with a value of “SMITH”, and the “Default New Value” to have a value of “FRED”.

As Forms is an official product, I’ve always found the best place to seek support is in the issue tracker. I’d suggest creating an issue there and linking it back in here.

Thanks for your comment and suggestion.

I’ve raised an issue here: Can’t set default values for Umbraco Form Field Type settings · Issue #1411 · umbraco/Umbraco.Forms.Issues

1 Like