I have created custom attributes on standard fields by following instructions in this post: Creating custom data attribute for Sitecore form fields E.g., Single line input, multi line input etc. I can populate them when in the content tree just fine:
And it renders the values on the page as you can see:
Problem is, when in forms designer mode, the values that I have entered in the content tree mode for my custom attributes dont get populated. If I manually re-enter them here and hit apply, they get cleared out.
Any idea what is going on? Did I miss a setting somewhere? Here is the model:
using System;
using Sitecore.Data.Items;
using Sitecore.ExperienceForms.Mvc.Models.Fields;
using Sitecore;
namespace Helix.Foundation.Forms.Fields
{
[Serializable()]
public class CustomSingleLineViewModel : StringInputViewModel
{
public string AriaLabel { get; set; }
public string AriaRequired { get; set; }
public string AutoComplete { get; set; }
protected override void InitItemProperties(Item item)
{
base.InitItemProperties(item);
AriaLabel = StringUtil.GetString(item.Fields["aria-label"]);
AriaRequired = StringUtil.GetString(item.Fields["aria-
required"]);
AutoComplete = StringUtil.GetString(item.Fields["autocomplete"]);
}
protected override void UpdateItemFields(Item item)
{
base.UpdateItemFields(item);
item.Fields["aria-label"]?.SetValue(AriaLabel, true);
item.Fields["aria-required"]?.SetValue(AriaRequired, true);
item.Fields["autocomplete"]?.SetValue(AutoComplete, true);
}
}
}
@using Sitecore.ExperienceForms.Mvc.Html
@model Helix.Foundation.Forms.Fields.CustomSingleLineViewModel
<input id="@Html.IdFor(m => Model.Value)" aria-label="@Model.AriaLabel" aria-
required="@Model.AriaRequired" autocomplete="@Model.AutoComplete"
name="@Html.NameFor(m => Model.Value)" class="@Model.CssClass" type="text"
value="@Model.Value" @if (Model.MaxLength > 0) { <text>
maxlength="@Model.MaxLength" </text> } placeholder="@Model.PlaceholderText"
data-sc-tracking="@Model.IsTrackingEnabled" data-sc-field-name="@Model.Name"
data-sc-field-key="@Model.ConditionSettings.FieldKey"
@Html.GenerateUnobtrusiveValidationAttributes(m => m.Value) />
<label for="@Html.IdFor(m => Model.Value)"
class="@Model.LabelCssClass">@Html.DisplayTextFor(t => Model.Title)</label>
<div>
@Html.ValidationMessageFor(m => Model.Value, "", new { @class = "sc-form-
validation" })
</div>