I have Created a custom Checkbox field type by duplicating the out of the box checkbox field type.
Only changed the View.
Ideally , my purpose is to get the display text (Model.Title in the code snippet )for the field from a rich text field which might contain a link.
I have not changed the model in my new custom field type. When add the field in a form , display is correct but when checkbox is checked from a page it is not saved in the DB.
Below is the View:
@using Sitecore.ExperienceForms.Mvc.Html
@model Sitecore.ExperienceForms.Mvc.Models.Fields.CheckBoxViewModel
@{
string dbName = Sitecore.Context.Database.Name == "core" || Sitecore.Context.Database.Name == "master" ? "master": "web" ;
Sitecore.Data.Database datbase = Sitecore.Configuration.Factory.GetDatabase(dbName);
var consentItem = datbase.GetItem(new Sitecore.Data.ID(Constants.FormConsentTextItem));
Model.Title = consentItem.Fields["ConsentText"].Value;
}
<label class="@Model.LabelCssClass">
<input type="checkbox" id="@Html.IdFor(m => Model.Value)" name="@Html.NameFor(m => Model.Value)" class="@Model.CssClass" @if (Model.Value) { <text> checked="checked" </text> } value="true" data-sc-tracking="@Model.IsTrackingEnabled" data-sc-field-name="@Model.Name" data-sc-field-key="@Model.ConditionSettings.FieldKey" @Html.GenerateUnobtrusiveValidationAttributes(m => Model.Value) />@Html.Raw(Model.Title)
<input type="hidden" name="@Html.NameFor(m => Model.Value)" value="false" />
</label>
@Html.ValidationMessageFor(m => Model.Value)