Copied to clipboard

Flag this post as spam?

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


  • Rob 22 posts 133 karma points
    Sep 21, 2017 @ 11:58
    Rob
    0

    Query the Value of a Radio Button not it's ID

    I have searched for this to no avail.

    I would like to select properties bases on the value of a radio button.

    So I have a radio button list for Bedrooms.

    I want to query all properties that have more than a selected amount of bedrooms.

    The number is stored as a radio button value between one and seven.

    berthV is a number between one and seven selected on a previous page.

    selectionNodes = CurrentPage.Children() .Where("documentTypeAlias == \"vehicleDetailPage\"") .Where("selectorBerth >= @0", berthV) .Where("Visible").OrderBy("createDate desc");

    I thought it would be as simple as that but selectorBerth is the ID of the button not it's actual value.

    Is this possible at this stage in the query

    Rob

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Sep 29, 2017 @ 16:21
    Alex Skrypnyk
    100

    Hi Rob

    What did you mean here?

    I want to query all properties that have more than a selected amount of bedrooms.

    All properties of current document? All documents?

    In the code example you are trying to get child nodes:

    selectionNodes = CurrentPage.Children() .Where("documentTypeAlias == \"vehicleDetailPage\"") .Where("selectorBerth >= @0", berthV) .Where("Visible").OrderBy("createDate desc");
    

    I would rewrite your code like that:

    int berthV = 3;
    var selectionNodes = Umbraco.AssignedContentItem.Children()
        .Where(x => x.DocumentTypeAlias.Equals("vehicleDetailPage"))
        .Where(x => x.HasValue("selectorBerth") && int.Parse(Umbraco.GetPreValueAsString(x.GetPropertyValue<int>("selectorBerth"))) >= berthV)
        .Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate);
    

    The most interesting code is:

    int.Parse(Umbraco.GetPreValueAsString(x.GetPropertyValue<int>("selectorBerth"))) >= berthV
    

    x.GetPropertyValue - returns id of value in radio button

    Umbraco.GetPreValueAsString - returns value of prevalue in string

    Hope it makes sense for you.

    Thanks,

    Alex

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Sep 30, 2017 @ 22:17
    Alex Skrypnyk
    0

    Hi Rob, did you solve the issue?

  • Rob 22 posts 133 karma points
    Oct 02, 2017 @ 09:24
    Rob
    0

    Hey Alex, I'll be working on it today I'll update later :)

    Rob

  • Rob 22 posts 133 karma points
    Oct 02, 2017 @ 16:52
    Rob
    0

    Thanks very handy. I get it now as my original code was returning the node number id not the content

    Cheers Rob

  • 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