Copied to clipboard

Flag this post as spam?

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


  • Arno 10 posts 111 karma points
    Apr 08, 2019 @ 08:12
    Arno
    0

    Checkbox (TrueFalse) Always returning False

    I'm trying to use the Checkbox/TrueFalse to toggle on/off certain parts of content, however it seems that no matter what setting I put the checkbox on, the Value (even parsed as Bool) always returns false.

    This is how I am doing:

    @if(item.Value<bool>("includeButton")) {
        ...
    }
    

    Any help appreciated. Thanks

  • Darren Welch 23 posts 136 karma points c-trib
    Apr 08, 2019 @ 09:13
    Darren Welch
    0

    That code is correct.

    As false is the default value for bool, I can only assume that there is an error in the property name. includeButton. Is the casing correct?

    You can check the alias name on the document type, to make sure it's not IncludeButton or includebutton etc.

    I assume item is part of a loop? If the alias is correct can you supply the full code?

  • Arno 10 posts 111 karma points
    Apr 08, 2019 @ 09:28
    Arno
    0

    Hi Darren,

    The alias is correct. Here is a complete piece of code:

    @{
       var whoweareLinks = Model.Value<IEnumerable<IPublishedElement>>("whoweareLinks");
       foreach(var linkBtn in whoweareLinks) {
          var content = linkBtn.Value<IPublishedContent>("link");
          if(content != null){
             var bg = linkBtn.Value<bool>("blueBackground");
             var btnClass = bg ? "Button Button--navy mr-4 mb-4" : "Button mr-4 mb-4";
             <a href="@content.Url" class="@btnClass">@linkBtn.Value("label")</a>    
          }
        }
     }
    

    And here is a screenshot of my button component:

    enter image description here

  • Darren Welch 23 posts 136 karma points c-trib
    Apr 08, 2019 @ 10:35
    Darren Welch
    0

    Sorry, I can't recreate this.

    I have set up a button element similar to yours: enter image description here

    recreated your code:

    @{
         var whoweareLinks = Model.Value<IEnumerable<IPublishedElement>>("components");
         foreach (var linkBtn in whoweareLinks)
         {
              var bg = linkBtn.Value<bool>("blueBackground");
              <p>@bg</p>
         }
     }
    

    and I see the correct values on the screen.

    True/False

    All of this is on version 8.0.1

    Umbraco 8 now uses nuCache for published content. So if you are sure the content is definitely published, maybe you could look at the cache:

    https://creativewebspecialist.co.uk/2018/07/30/peek-inside-umbraco-v8-nucache-files-with-the-nucache-explorer-tool/

  • Arno 10 posts 111 karma points
    Apr 08, 2019 @ 14:48
    Arno
    0

    I have no idea it's proper weird. The checkbox is working when I add a simple checkbox property on my document type, but not working when it's coming from a component in a nested content.

  • Darren Welch 23 posts 136 karma points c-trib
    Apr 08, 2019 @ 15:51
    Darren Welch
    0

    Do you have multiple languages on your site? You can pass in the culture info to get the correct version:

    linkBtn.Value<bool>("blueBackground", "culture" )
    
  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Apr 08, 2019 @ 17:19
    Bjarne Fyrstenborg
    100

    Hi Arno

    My guess is that you are running on Umbraco v8.0.0, which had this issue: https://github.com/umbraco/Umbraco-CMS/issues/4812

    The fix https://github.com/umbraco/Umbraco-CMS/pull/4819 has been included in Umbraco v8.0.1

    https://our.umbraco.com/download/releases/801

    /Bjarne

  • Kristian Ravnevand 94 posts 214 karma points
    Oct 30, 2020 @ 08:33
    Kristian Ravnevand
    0

    If this occured after you have added a new bool to a document type, I fixed it by running "Reload Memory Cache" on Settings > Dashboard > Published Status

    (On Umbraco 8.7)

Please Sign in or register to post replies

Write your reply to:

Draft