Xform Checkbox selected or not value in MVC

Vote:
 

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.

#72640
Jun 25, 2013 12:46
Vote:
 

Also experiencing this in 7.5.  

#85135
Apr 16, 2014 9:59
Vote:
 

Did you ever solve this?

#87475
Jun 13, 2014 14:48
Vote:
 
@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 :)

#87597
Jun 17, 2014 17:25
Vote:
 

This behaviour seems to be random, we got select working nicely without custom rendering but then again it started to fail. WTF?

#89811
Aug 26, 2014 17:21
Vote:
 

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....

#89820
Aug 27, 2014 1:33
Vote:
 

... 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.

#89821
Aug 27, 2014 1:48
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.