CheckBoxList Form Component

Yowaraj Chhetri asked on October 13, 2020 05:05

Hi there,

I am trying to develope custom checkbox list form component for form builder. However, i am stuck with one problem that checkbox is not checked and having problem of autopostback.

Below is the checkboxlist in form builder and live site. In live site, checkbox is not checked.

Where am i getting wrong, or how do I go about building custom multiselect form component.

checkboxlist

checkboxlistin-live-site
<a target='_blank' href='https://imgbb.com/'>html center image

My partialview code is as follows:

@model FormComponents.CheckBoxListComponent

    @{ foreach (var item in Model.Items) {
  • @Html.CheckBoxFor(m => item.Selected) @Html.DisplayFor(m => item.Text)
  • } }

Thanks in advance

Recent Answers


Yowaraj Chhetri answered on October 13, 2020 06:46

Actually that problem is resolved with

    foreach (var item in Model.Items)
    {
        <li>
            @Html.CheckBox("Options",false, htmlAttributes)
            @Html.DisplayFor(m => item.Text)
        </li>
    }

Howver, how would I bind the checkbox value and save it as form record in cms. I am using Options properties of the form which is a default/system property. I am using SelectorProperties and SelctorFormComponent

public class CheckBoxListComponent : SelectorFormComponent<CheckBoxListComponentProperties>
{
    public const string IDENTIFIER = "CheckBoxListComponent";

    [BindableProperty]
    public string Options { get; set; }

    public override string GetValue()
    {
        return Options;
    }

    public override void SetValue(string value)
    {
        if (!string.IsNullOrEmpty(value))
        {
            Options = value;
        }
        else
        {
            SetValue("All");
        }
    }

}

  public class CheckBoxListComponentProperties : SelectorProperties
{
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.