Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Henning Molbaek 49 posts 99 karma points
    May 02, 2013 @ 09:03
    Henning Molbaek
    0

    Checkbox checked at default

    How do you check a checkbox by default in your form?

    Been reading about "hacking" source to do this. Hopefully this is not nessecary on a paid pro module?

  • Comment author was deleted

    May 02, 2013 @ 10:17

    Hey,

    Just set the default value to true

     

  • Henning Molbaek 49 posts 99 karma points
    May 02, 2013 @ 10:24
    Henning Molbaek
    0

    I did but that does not make it checked.

    http://thy360.dk/branding-af-thy/vind-en-ipad.aspx

  • Comment author was deleted

    May 02, 2013 @ 10:26

    Ok looks like it's a bug, will release an update today but to fix it you can simply update 

    \Umbraco\Plugins\umbracoContour\Views\FieldType.CheckBox.cshtml 

    and add

    @if(Model.ContainsValue(true) || Model.ContainsValue("true"))

    where it says

    @if(Model.ContainsValue(true))

  • Henning Molbaek 49 posts 99 karma points
    May 02, 2013 @ 14:58
    Henning Molbaek
    0

    Great but one minor bug. If you don't fill out a mandatory field and hit submit it leaves the checkbox now "un-checked."

  • Comment author was deleted

    May 03, 2013 @ 11:19

    Ok issue added to the issue tracker http://issues.umbraco.org/issue/CON-356

  • Bjørn Fridal 274 posts 784 karma points
    May 03, 2013 @ 12:06
    Bjørn Fridal
    0

    I have the same problem with checkboxes being unchecked, if the form fails to be submitted. Any chance of a workaround?

    Cheers
    Bjørn 

  • Comment author was deleted

    May 06, 2013 @ 12:38

    @Bjorn,

    Yeah update the \Umbraco\Contour\Code WEBFORMS\FormsSampleSite\Umbraco\Plugins\umbracoContour\Views\FieldType.CheckBox.cshtml file

    and where it says @if (Model.ContainsValue(true)) add || Model.ContainsValue("on")

  • Bjørn Fridal 274 posts 784 karma points
    May 06, 2013 @ 14:28
    Bjørn Fridal
    0

    Thanks but that doesn't seem to work when you have defined a default value. Then the checkbox is always selected, also when its unselected.

    Cheers
    Bjørn 

  • Bjørn Fridal 274 posts 784 karma points
    May 17, 2013 @ 10:39
    Bjørn Fridal
    0

    Used the following workaround:

    bool isChecked = IsPost ? Request.Form[Model.Id] == "on" : Model.ContainsValue("true");

    Cheers
    Bjørn

Please Sign in or register to post replies

Write your reply to:

Draft