Copied to clipboard

Flag this post as spam?

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


  • Ajay Karwal 31 posts 149 karma points
    Sep 10, 2015 @ 14:58
    Ajay Karwal
    0

    Get Radio Button List prevalue Value, not text.

    I have a Radio button list data type on my Doctype (status) where the editor can set the status of a product (i.e. in Stock, Sold Out, Pre-Order)

    I am able to get the prevalue text of the selected option using

    if (CurrentPage.HasValue("status")) {
      var skuStatusText = Umbraco.GetPreValueAsString(CurrentPage.status);
    }
    

    I want to use the status to add a class to change the state of the Buy button to be enabled, disabled or hidden via a switch-case statement.

    The problem is, these text labels will eventually be multi-lingual so are no good for using in the my switch-case. I need to get the value/id of the chosen radio button but cannot figure out how.

    My full block of code so far... (which doesn't actually work)

    if (CurrentPage.HasValue("status")) {
      var skuStatusText = Umbraco.GetPreValueAsString(CurrentPage.status);
      var btnState = "";
    
      switch (@skuStatusText)
      {
        case "Pre-Order":
          btnState = "disabled";
          break;
        case "Buy Now":
          btnState = "";
          break;
      }
      <a href="#" class="btn btn-primary btn-lg @btnState">
        @skuStatusText
      </a>
    }
    

    Cant seem to find any way of getting the value/id of the chosen radio button.

  • Ajay Karwal 31 posts 149 karma points
    Sep 14, 2015 @ 15:15
    Ajay Karwal
    0

    Still looking for some help on this.

    Anyone?

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Sep 14, 2015 @ 15:30
    Nik
    0

    Hi Ajay,

    Have you tried just writing out CurrentPage.Status without trying to get the pre-value and see what it contains?

  • Ajay Karwal 31 posts 149 karma points
    Sep 14, 2015 @ 15:50
    Ajay Karwal
    101

    I had been approaching the problem all wrong.

    The reason I wanted the Values was because the site is multilingual but really all I need to do is replace the value of @skuStatusText based on the prevalue (which can be in English seeing as it's never being displayed.

    I've changed my whole code block to the following for reference to anyone else reading this

                @{
    
                    if (CurrentPage.HasValue("status"))
                    {
                        var skuStatusText = Umbraco.GetPreValueAsString(CurrentPage.status);
    
                        var btnState = "";
                        if (@skuStatusText == "Out Of Stock")
                        {
                            skuStatusText = @Umbraco.Field("#[Button] Out of Stock", altText: "Out of Stock", recursive: true);
                            btnState = "disabled";
                        }
                        else if (@skuStatusText == "Available Soon")
                        {
                            skuStatusText = @Umbraco.Field("#[Button] Available Soon", altText: "Available Soon", recursive: true);
                            btnState = "disabled";
                        }
                        else if (@skuStatusText == "Pre-Order")
                        {
                            skuStatusText = @Umbraco.Field("#[Button] Pre-Order", altText: "Pre-Order", recursive: true);
                        }
                        else
                        {
                            skuStatusText = @Umbraco.Field("#[Button] Buy Now", altText: "Buy Now", recursive: true);
                        }
    
                        <a href="#" class="btn btn-primary btn-lg @btnState">
                            @skuStatusText
                        </a>
                    }
                }
    
Please Sign in or register to post replies

Write your reply to:

Draft