Copied to clipboard

Flag this post as spam?

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


  • Mark Watson 118 posts 380 karma points
    May 28, 2018 @ 03:55
    Mark Watson
    0

    Hide date field if empty

    I am new to Umbraco. I have created two properties Event Start Date and Event End Date with the Date picker. I wish to hide the End Date if the field is empty. ie the event is only a single day. Currently it displays Monday 01/01/0001 if it is left empty. How do I do that?

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 28, 2018 @ 06:10
    Dennis Aaen
    0

    Hi Mark

    What you can do is use the method called HasValue() this will only print the value out if there is one

    It looks something like this

    @if(Model.Content.HasValue(eventEndDate)){

    Do something if the field has a value

    }

    Remember ro change the eventEndDate so it match your field alias

    Hope this helps,

    /Dennis

  • Mark Watson 118 posts 380 karma points
    May 29, 2018 @ 04:46
    Mark Watson
    0

    Thanks Dennis

    But I could not work out how to get this to work.

    Original

    @(item.GetPropertyValue<DateTime>("eventStartDate").ToString(" dddd dd/MM/yyyy")) - @(item.GetPropertyValue<DateTime>("eventEndDate").ToString(" dddd dd/MM/yyyy"))
    

    What I tried

    @if(Model.Content.HasValue("eventEndDate")){  @(item.GetPropertyValue<DateTime>("eventEndDate").ToString(" dddd dd/MM/yyyy"))}
    
  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 29, 2018 @ 06:07
    Dennis Aaen
    1

    @if(item.HasValue(“eventEndDate”)){

    // output the value from the date picker here

    }

    If eventEndDate now has a value then it will be printed out

    Hope this helps

    /Dennis

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies