Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 660 karma points
    Aug 23, 2018 @ 12:44
    Martin
    1

    Hi all,

    Im looking to set the default value on a radio button list.

    Any help would be grateful. Martin

    @if (Model.HasValue("radioButton"))
    {
        var preValue = Umbraco.GetPreValueAsString(Model.GetPropertyValue<int>("radioButton"));
        <h1 @preValue</h1>
    }
    
  • Jan Skovgaard 11245 posts 23441 karma points MVP 6x admin c-trib
    Aug 23, 2018 @ 13:55
    Jan Skovgaard
    0

    Hi Martin

    I'm a little bit confused here - Are you in fact trying to render a list of radio buttons where you want to have one of them being set marked by default?

    Or is is that you want to render the selected radio button from the Umbraco backoffice in a <h1> element? If so...I can imagine you receive an error currently since the the opening tag is not formatted correctly. For what I can see the preValue variable looks like it's been setup correctly.

    So can you try fixing the <h1 @prevalue</h1> to be <h1>@preValue</h1> - Sorry if I misunderstand but then please let me know :)

    /Jan

  • Martin 278 posts 660 karma points
    Aug 24, 2018 @ 11:12
    Martin
    0

    Sorry Jan,

    Im being stupid.

    I was wanting to setup a radio button list that has three options and have a default selected in the backend.

  • Jan Skovgaard 11245 posts 23441 karma points MVP 6x admin c-trib
    Aug 24, 2018 @ 20:49
    Jan Skovgaard
    1

    Hi Martin

    No worries mate :-)

    Hmm, I'm not sure that it's currently possible. I recall I've seen other posts asking about how to do this since I remember thinking about having a look at maybe extending the property editor to allow for such scenario. But I have not come around to it yet though :) - Not sure when/if I will. It's on my list of ideas though.

    I can't remember if perhaps something like it can be achieved using NuPickers though?

    /Jan

  • Chris 12 posts 84 karma points
    Sep 24, 2018 @ 10:43
    Chris
    1

    I too would like to be able to set the value of a radiobutton list from a surface controller. Mine would be in members.

    Looks like I just need to get the Id of the radio button. We know the string value so a function to return the Id (value) from a string (text) would be great.

    SOLUTION:

    I have managed to set a value using IMember class supplied by MemberService. Create your radiobutton list and select the value you want to default to. Print the value to screen or debug to get it.

    int approvalValue = IPublishedContent.GetPropertyValue<int>("radioButtonList");
    

    I was able to use to below to set the int value of the radiobutton I wanted to Set:

    IMember.SetValue("radiobuttonList", 112);
    

    @Martin As a workaround, you should be able to check the value in the ContentService.Published event and if value is not set (int value 1 for me), set the default value you want.

Please Sign in or register to post replies

Write your reply to:

Draft