Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 14, 2014 @ 17:54
    Fuji Kusaka
    0

    Displaying html msg once only when using a checkbox

    Hi everyone,

    I have a simple custom dataType Checkbox with 4 different values and would like to make a simple filtering which works well but would also like to display a message whenever the expected value is not being checked.

    here is the piece of code

    foreach(var item in news.Where(x=>x.GetProperty("umbracoNaviHide").Value != "1" && x.GetProperty("nhl").Value.ToString() != String.Empty).OrderByDescending(y=>y.CreateDate).Take(5)){
     
    if(item.GetProperty("newsHotel").Value == "VPV"){
    foreach(var n in item.GetProperty("nhl").Value.Split(',')){
    if(n.ContainsAny("VPV")){
    <li><a href="@item.Url">@item.Name</a></li> }
    } } else{ @:No Data // here this msg should appear only once
    }
     }
     }

     

    No Data message should display once only but giving me the multiple No Data taking all the nodes with checked boxes.

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 14, 2014 @ 20:25
    Fuji Kusaka
    0

    Any suggestion on how i might proceed on this anyone ?

  • Brian Reimer 30 posts 120 karma points
    Jan 15, 2014 @ 07:07
    Brian Reimer
    0

    what about setting a variable in the else (no data) and only showing it after the foreach - if it's set.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 15, 2014 @ 08:24
    Fuji Kusaka
    0

    Not sure if this will work but will give it a shot.....

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 08:25
    Jeavon Leopold
    0

    Hi Fuji,

    I don't fully understand what you are trying to do, how are newsHotel and nhl related? Perhaps you could add screenshot of your content?

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 15, 2014 @ 09:10
    Fuji Kusaka
    0

    Hi Jeavon,

    Ah sorry i miss type this part, they are both the same.

    foreach(var item in news.Where(x=>x.GetProperty("umbracoNaviHide").Value!="1"&& x.GetProperty("nhl").Value.ToString()!=String.Empty).OrderByDescending(y=>y.CreateDate).Take(5)){
     
       if(item.GetProperty("nhl").Value=="VPV"){
            foreach(var n in item.GetProperty("nhl").Value.Split(',')){
              if(n.ContainsAny("VPV")){
                    <li><a href="@item.Url">@item.Name</a></li>
                  }
            }
      }
      else{
          @:NoData// here this msg should appear only once
           }
         }
     
    }

     

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 10:01
    Jeavon Leopold
    0

    Ok, in that case let's consider that nhl contains the value "VPV,ABC" the if will not match so we are in the else, but if nhl contains "VPV" then we are in the if but the foreach is only going to have one iteration?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 15, 2014 @ 10:15
    Fuji Kusaka
    0

    So if "n.ContainsAny("VPV")" it should display the nodes. But at the moment its displaying both the @:No Data since some of the nodes does not have "VPV" checked but other checked boxes.

     


  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 19:41
    Jeavon Leopold
    0

    Sorry, I'm still slightly confused, I have simplified your code to the below:

    foreach (var item in news.Where(x => x.Visible && x.HasValue("nhl")).OrderByDescending(y => y.CreateDate).Take(5))
    {
        if (item.GetPropertyValue("nhl") == "VPV")
        {
            foreach (var n in item.GetProperty("nhl").Value.Split(','))
            {
                if (n.ContainsAny("VPV"))
                {
                    <li><a href="@item.Url">@item.Name</a></li>
                }
            }
        }
        else
        {
            @:NoData// here this msg should appear only once
        }
    }
    

    Now I have one node with the value "VPV" and one node with the value "MMM" in the property alias "nhl", the output I get is what I would expect.

    MNTP
    NoData// here this msg should appear only once
    

    Now I change the value of the first node to "VPV,MMM", I get

    NoData// here this msg should appear only once 
    NoData// here this msg should appear only once
    

    Am I right in saying that what you are after is to get the same output as my first example?

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 15, 2014 @ 19:56
    Fuji Kusaka
    0

    Youre right !

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 19:57
    Jeavon Leopold
    0

    Ah ha, ok, so here is how I would do it:

    @{
    
        var news = SOMETHINGIDONTKNOW;
    
        foreach (var item in news.Where(x => x.Visible && x.HasValue("nhl")).OrderByDescending(y => y.CreateDate).Take(5))
        {
            if (IdContained(item.GetPropertyValue("nhl"),"VPV"))          
            {               
                <li><a href="@item.Url">@item.Name</a></li>               
            }
            else
            {
                @:NoData// here this msg should appear only once
            }
        }
    }   
    
    @functions{
    
        private static bool IdContained(string valueCsv, string valueId)
        {
            if (string.IsNullOrEmpty(valueCsv))
            {
                return false;
            }
            var idCheckList = valueCsv.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            return idCheckList.Contains(valueId);
        }
    
    }
    
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 20:02
    Jeavon Leopold
    0

    If you didn't actually need to show the "No data" bit you could filter on the collection, of course you would then get 5 nodes that matched only, e.g:

    @{    
        var news = SOMETHINGIDONTKNOW;
    
        foreach (var item in news.Where(x => x.Visible && x.HasValue("nhl") && IdContained(x.GetPropertyValue("nhl"),"VPV")).OrderByDescending(y => y.CreateDate).Take(5))
        {          
                <li><a href="@item.Url">@item.Name</a></li>               
        }
    }   
    
    @functions{
    
        private static bool IdContained(string valueCsv, string valueId)
        {
            if (string.IsNullOrEmpty(valueCsv))
            {
                return false;
            }
            var idCheckList = valueCsv.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            return idCheckList.Contains(valueId);
        }
    
    }
    
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 20:10
    Jeavon Leopold
    0

    Actually, I think my IdContained function is the same as the ContainsAny method, so this should work:

    foreach (var item in news.Where(x => x.Visible && x.HasValue("nhl")).OrderByDescending(y => y.CreateDate).Take(5))
    {
        if (item.GetPropertyValue("nhl").ContainsAny("VPV"))
        {               
            <li><a href="@item.Url">@item.Name</a></li>               
        }
        else
        {
            @:NoData// here this msg should appear only once
        }
    }
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 15, 2014 @ 20:32
    Fuji Kusaka
    0

    Hi Jeavon,

    Did tried those but still not working

    if(item.GetPropertyValue("nhl").ContainsAny("VPV")){
    foreach(var n in item.GetProperty("nhl").Value.Split(',')){
    if(n.ContainsAny("VPV")){
    <li><a href="@item.Url">@altTit</a></li>
    }
    }
               }
    else{
    @:NoData// here this msg should appear only once
    }

    Am still getting all the nodes with the checked box "VPV" with No Data being displayed as well since.

    Each node has a list of 4 checkboxes and on the template "VPV" only nodes with "VPV" should be displayed.

    Thanks for your help on this.

     

     

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 15, 2014 @ 20:43
    Jeavon Leopold
    0

    Hi Fuji,

    nhl is a CheckBoxList, right?

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 16, 2014 @ 05:45
    Fuji Kusaka
    0

    Yes it is. Sorry for late reply

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 16, 2014 @ 10:22
    Fuji Kusaka
    0

    This seems to be working right now.

     var tt = @Model.AncestorOrSelf(2).Descendants("vrn");
    @if(tt.Where("nhl.Contains(\"VPV\")").Count() > 0){
                   foreach(var t in tt.Where("nhl.Contains(\"VPV\")")){
                                   @t.Name <br />
                       }
                                     
            }

     

     

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 16, 2014 @ 20:31
    Jeavon Leopold
    0

    Great, glad it's working for you, I am completely lost, so sorry!

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 17, 2014 @ 11:54
    Fuji Kusaka
    0

    Thanks Jeavon for you help though.  Instead of displaying the message "No Data" whenever no "VPV" is checked from the list, i instead created a make a test from the list itself.

     var tt = Model.AncestorOrSelf(2).Descendants("somenodes");
    If any of them has "vpv" checked then the whole container is being displayed.
    //fuji
                
Please Sign in or register to post replies

Write your reply to:

Draft