@using EPiServer.XForms.Parsing
@model SelectFragment
<fieldset>
<legend>
@Model.Label
</legend>
@foreach (SelectOption selectoption in Model.Options)
{
<div class="checkbox @(Model.Class.IsEmpty() ? "col-sm-12" : Model.Class)">
<label>
<input id="@selectoption.Id" name="@selectoption.Id" type="checkbox" value="true">
<input name="@selectoption.Id" type="hidden" value="false">
@selectoption.Value
</label>
</div>
}
@Html.ValidationMessage(Model.ValidationReference)
</fieldset>
Yepp, it works with the following code.
Wish it would have been solvable with Html.Checkbox, but I guess not :)
This behaviour seems to be random, we got select working nicely without custom rendering but then again it started to fail. WTF?
Found reason for this "random" behaviour: It was a freaking dot (.) character in the checkbox option value.
In EPiServer SelectOption.Id is generated by taking SelectFragment.Reference + SelectOption.text. EPiServer renders checkboxes by default using HTML.Checkbox helper, and SelectOption.Id is passed to it as the name for the checkbox. We had dot character in our SelectOption.Text property.
Seems that dot character is dropped out from name in this rendering process, which caused the value that was sent when checkbox was selected not to match the Option name in XForm defined in EPiServer.
IMHO SelectOption.ID should be generated some other way as the Text property can contain whatever characters causing potentially problems.
So small issue and so much pain....
... And as a postscript: The solution Jonas presented should have worked in theory as it bypasses the HTML.Checkbox and renders checkbox directly. But then I ran to next problem with id attribute as html attribute id can only contain limited set of characters, for example spaces are not allowed. But it must be unique so to be able to use SelectOption.Id one must first escpage/clean the SelectOption.Id so that it is valid string for html id attribute.
Do anyone know how to get if the checkbox is selected or not by the user in the XForm checkbox. I used Key/value to get the value for
the XformData. but for Checkbox its always gives empty.