Hey there! Interesting issue here. I've got a custom form control built to allow for multi-select checkbox fields. The form control seemingly works great. The checkboxes are built out correctly and everything appears well....until you click one. It selects the box, then unchecks it almost immediately. You can't check any of the boxes. I am wondering if the Kentico build scripts for the form builder are doing something here? You can preview the issue here (you need to check @yes@ to the true/false question, as its conditional): https://dev.caos.carle.org/about/contact-usHere is my implementation code for the form component:Form Component Itselfusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CAOS.Models.FormComponents;
using Kentico.Forms.Web.Mvc;
[assembly: RegisterFormComponent(MultiselectCheckboxComponent.IDENTIFIER, typeof(MultiselectCheckboxComponent), @Multi-select Checkbox@, Description = @Allows users to add a multi select checkbox field.@, IconClass = @icon-cb-check-preview@)]
namespace CAOS.Models.FormComponents
{
public class MultiselectCheckboxComponent : FormComponent@MultiselectCheckboxComponentProperties, string@
{
public const string IDENTIFIER = @MultiselectCheckboxComponent@;
[BindableProperty]
public string CheckboxValue { get; set; }
public override string GetValue()
{
return CheckboxValue;
}
public override void SetValue(string value)
{
if (!String.IsNullOrEmpty(value))
{
CheckboxValue = value;
}
else
{
CheckboxValue = @@;
}
}
}
}
Form Component Propertiesusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CAOS.Models.FormComponents;
using CMS.DataEngine;
using Kentico.Forms.Web.Mvc;
namespace CAOS.Models.FormComponents
{
public class MultiselectCheckboxComponentProperties : FormComponentProperties@string@
{
[DefaultValueEditingComponent(TextInputComponent.IDENTIFIER, DefaultValue = @@)]
public override string DefaultValue { get; set; }
[EditingComponent(TextAreaComponent.IDENTIFIER, DefaultValue = @@)]
public string MultiselectItems { get; set; }
public MultiselectCheckboxComponentProperties() : base(FieldDataType.LongText)
{
}
}
}
ANDDDD the view:@using Kentico.Forms.Web.Mvc
@using CAOS.Models.FormComponents
@using CAOS.FormBuilder.Models
@using System.Collections.Generic
@model MultiselectCheckboxComponent
@{
var htmlAttributes = ViewData.GetEditorHtmlAttributes();
List@Checkbox@ options = new List@Checkbox@();
string[] optionsSplit = Model.Properties.MultiselectItems.Split('|');
foreach(var option in optionsSplit)
{
string[] splitOption = option.Split(';');
Checkbox cb = new Checkbox();
cb.Checked = false;
cb.Label = splitOption[0];
cb.Value = splitOption[1];
options.Add(cb);
}
}
@div class=@grid-container noPaddingX@@
@div class=@grid-x@@
@foreach (var option in options)
{
@div class=@large-4 medium-6 small-12 cell@@
@div class=@multi-checkbox@@
@input type=@checkbox@ name=@checkbox-@Model.BaseProperties.Guid@ value=@@option.Value@ id=@@option.Value.Replace(@ @, @@).ToLower()@ /@
@label for=@@option.Value.Replace(@ @, @@).ToLower()@@@option.Label@/label@
@/div@
@/div@
}
@/div@
@/div@
↧