0

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: enter image description here

And it renders the values on the page as you can see: enter image description here

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. enter image description here

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>
2
  • Could you please add code as well, which you have done? Commented Apr 27, 2020 at 17:50
  • @SwatiGupta. Model and view added.
    – SeeSharper
    Commented Apr 27, 2020 at 19:45

2 Answers 2

2

I was also facing the same issue. In core DB, property editor settings - binding configuration, the model property should be in camel case. Once I added the model property in camel case, the issue was fixed. In you case, ariaLabel, ariaRequired etc

enter image description here

0

Can you please try to add autocomplete value in code db like below:

enter image description here

1
  • Yes. I already have autocomplete there.
    – SeeSharper
    Commented Apr 29, 2020 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.