Copied to clipboard

Flag this post as spam?

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


  • Neil 63 posts 105 karma points
    Nov 08, 2013 @ 19:31
    Neil
    1

    How to use multi-node tree picker to filter child nodes based on a document property value

    Using umbraco 4.7, and want to generate a list of nodes selectable in a document property in another node.  I have a large group of child nodes of a certain document type which has a truefalse checkbox for one of its document properties. I want to make my list from these child nodes, but want to filter it so that only those with the checkbox checked appear in the list.  

    I'm using multi-node tree picker, but the xpath expression obviously only returns the first match, and since multi-node tree picker only allows an xpath expression (i.e., you can't have a for loop), I'm not sure how to generate the list.

    Any way around this?  Is there another data type that would allow this kind of filtering other than multi-node tree picker?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 08, 2013 @ 21:42
    Chriztian Steinmeier
    0

    Hi Neil,

    I think you should be able to use the XPath filter — if you say "/*[checkboxPropertyAlias = 1]" and tick the "Enable" radio, only nodes with that property checked will be selectable.

    You may want to try the XPath CheckBoxList datatype too. It will only show allowed nodes (based on an XPath), but won't let you sort them though...

    /Chriztian

  • Neil 63 posts 105 karma points
    Nov 08, 2013 @ 21:57
    Neil
    0

    Hi Chriztian,

    My node/doc type hierarchy goes homePage/investmentsPage/investmentPage, where investmentPage has the checkbox property I want to test.

    In line with your first suggestion, my xpath expression looked like this: 

    $ancestorOrSelf/ancestor-or-self::root/homePage/investmentsPage/investmentPage [@isDoc and string(showInPMC) = '1']

    with the radio button set to Enable.  What happens is, it returns only the first node of type investmentPage that has showInPMC set to 1.  I'm no xpath wiz, but note that in xslt scripts, you have to do a for each loop to grab all the nodes that satisfy this condition.  Each test returns only one.  Isn't that true and doesn't that mean I can't get all in a list at once?  It seems that in multi-node tree picker, the xpath expression is meant to get you to a parent node from whose children you want to select, but not to filter the children themselves.  I'd have to put all investmentPage nodes that have this showInPMC flag set under a separate parent node, which of course defeats the purpose of having it be a flag you can set and then filter on in code elsewhere.

    Any other insight you have would be appreciated.

    I'll look into XPath CheckboxList and see what it offers.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 08, 2013 @ 22:16
    Chriztian Steinmeier
    101

    Hi Neil,

    Contrary to what most people think, you don't have to use for-each to get all the nodes in a selection - but that's another story :-)

    Here, with the MNTP you're kind of right, though - the thing is that you have two places to put an XPath - the first one is to get the starting node of the tree to select from; the second one is used for filtering the nodes. The starting node XPath will be "hardwired" to only use the first node returned (says so somewhere) - but that's a special case for this datatype.

    So it sounds to me like you can just use the "Content picker" option for the starting node, and then use the simpler XPath in the filter section.

    Does that make sense?

    /Chriztian

  • Neil 63 posts 105 karma points
    Nov 08, 2013 @ 22:22
    Neil
    0

    It does!  And it works...though it's an awfully ugly way to display the results.  Why not just show the selectable nodes neatly instead of the parent and then all the ones you can't select in red...?

    Oh well, it'll do the trick!  Thanks for the help, Chriztian.  You're usually the one who answers my questions!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 08, 2013 @ 22:38
    Chriztian Steinmeier
    0

    Ah, interesting - haven't heard that one before, actually (the "awfully ugly" comment).

    I guess the idea is that for many uses you're showing almost the entire Content tree, and the editor will be able to select a majority of them. I'd say your use-case lends itself to the XPath CheckBoxList, as it'll do what you were expecting here (one-level list of selectable items).

    My brother and I did a talk at the Umbraco DK Festival this year (so slides are in danish) where a section was about the different ways to do what we called "Widgets", depending on the client's needs/mood/general feel — if you start at this slide and go forward, you can atleast see the difference between them, if you're curious...

    /Chriztian

  • Neil 63 posts 105 karma points
    Nov 08, 2013 @ 22:51
    Neil
    0

    I see the rationale, and you're right, it just doesn't best suit my use case.  Of course xpath checkboxlist in theory is more targeted, but these investment nodes my vary widely in what proportion of them are selectable for display in this other locale, so it may become unwieldy to have checkboxes.  Translation:  I'll live with the red!

    I'll definitely check out the slides for more info.  Thanks again.

Please Sign in or register to post replies

Write your reply to:

Draft