Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    Sep 17, 2014 @ 10:05
    Daniel Larsen
    0

    Alert code does not work, but why?

    Hello guys!

    I am stuck with this small problem, where I have 3 different textboxes  on my home page, to show an alert message on all other pages. It is displaying my message nicely, but it displays the wrong color. It is like it takes the message correctly and then just takes the first statement from the if-statement. If you need more info, please just write!

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
    var alert = "";
    var message = "";
    var red = "warning";
    var yellow = "error";
    var green = "success";
    var root = Model.AncestorOrSelf(1);

    if(!String.IsNullOrEmpty(root.Warning)) 
    {
    alert = red;
    message = root.Warning;
    }
    else if(!String.IsNullOrEmpty(root.Error)) 
    {
    alert = yellow;
    message = root.Error;
    }
    else if(!String.IsNullOrEmpty(root.Success)) 
    {
    alert = green;
    message = root.Success;
    }
    else 
    {
    alert = "";
    message = "";
    }

    if(!String.IsNullOrEmpty(root.Warning) || !String.IsNullOrEmpty(root.Error) || !String.IsNullOrEmpty(root.Success))
    {
    <div class="row">
            <div id="alert" class="small-12 columns @alert">
                <p>@message</p>
            </div>
        </div>
    }
    }

    Please help me! 

    Thank you. :-)

    /Daniel

  • Bjarne Fyrstenborg 1281 posts 3991 karma points MVP 8x c-trib
    Sep 17, 2014 @ 11:22
    Bjarne Fyrstenborg
    0

    Hi Daniel

    Does the warning textbox contains any value? if it does the match the first condition and won't validate the other conditions, so the alert variable contains the value red.

    /Bjarne

  • Bjarne Fyrstenborg 1281 posts 3991 karma points MVP 8x c-trib
    Sep 17, 2014 @ 11:26
    Bjarne Fyrstenborg
    0

    Any reason why you have three textboxes and not just a single one and have a switch block returning different values based on the value of the textbox? or use a dropdown with the values "Warning", "Error" and "Success"?

  • Daniel Larsen 116 posts 381 karma points
    Sep 17, 2014 @ 13:20
    Daniel Larsen
    0

    You are right. I will try the dropdown option in stead and return with the result. Thank you :-)

Please Sign in or register to post replies

Write your reply to:

Draft