Copied to clipboard

Flag this post as spam?

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


  • Henrik Vincent 122 posts 616 karma points
    Aug 03, 2017 @ 11:17
    Henrik Vincent
    0

    Don't show date/time if empty

    Hi guys

    I've been working on a calendar with special dates.

    I added two date/time pickers for starting time and end time.

    I want the end time only to be shown, if it has been filled out with a specific date. This is only for when the event duration is more than a day.

    My code is as follows:

    <div id="@item.Name" class="panel-collapse collapse">
          @{
              var children = item.Children().Where(x => x.IsVisible() && x.DocumentTypeAlias == "dag").ToList().OrderBy("startdato");
          }
          @if (children.Any())
          {
              <ul class="list-group">
                  @foreach (var subpage in children)
                  {
                      <li class="list-group-item"><p><span>@subpage.GetPropertyValue("maerkedag")</span><span>@(subpage.GetPropertyValue<DateTime>("startdato").ToString("dd/MM/yyyy"))</span>
                      if(!subpage.GetPropertyValue("slutdato") == true){
                        <span style="display:none;"> - @(subpage.GetPropertyValue<DateTime>("slutdato").ToString("dd/MM/yyyy"))</span></p></li>
                        }
                  }
              </ul>
          }
    </div>
    

    I took the if statement, from another project I did, but it doesnt seem to translate to what I need in this case.

    Hope you guys can give me a push in the right direction

    Best

    Henrik

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 03, 2017 @ 12:47
    Dennis Aaen
    101

    Hi Henrik

    Could you please try this to see if it works for you

    if(subpage.HasValue("slutdato")){
                        <span style="display:none;"> - @(subpage.GetPropertyValue<DateTime>("slutdato").ToString("dd/MM/yyyy"))</span></p></li>
                    }
    

    Hope this helps,

    /Dennis

  • Henrik Vincent 122 posts 616 karma points
    Aug 04, 2017 @ 06:21
    Henrik Vincent
    0

    Hi Dennis

    Thank you very much!

    After rearranging my code a bit I got it working with your suggestion.

    This solution is way simpler than what I was trying to achieve with my first code.

    So once again. Thank you very much.

    Have a great one :)

    Best

    Henrik

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 04, 2017 @ 06:54
    Dennis Aaen
    0

    Hi Henrik,

    Great to hear that it worked for you. Happy that I could help you out.

    Have a fantactic Friday and weekend.

    All the best,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft