Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Mar 24, 2014 @ 07:10
    syn-rg
    0

    Create dropdown menu based on preValues and node properties

    I'm creating a select menu, I have a dropdown list data type, which I use to apply various values to my media items.

    Business names:

    1. Apple
    2. Orange
    3. Banana

    Using the multiple media picker I select which media items I wish to relate to my page, then create a list of the selected media items.

    I want the dropdown list to only appear if there is more than one Business name present in the selected list of media items.

    e.g. 5 selected media items have the business name value, Apple, and 3 selected media items have the business name value, Banana.

    If there had been 5 Apple's, then the dropdown list wouldn't appear.

    Also I want the dropdown list options to display, only if a selected media item shares that value. Using the above example, the dropdown list would only display options for Apple and Banana, not Orange.

    I've been trying to figure out what I need to compare each media items value, against the preValues of my datatype. But I can't figure out how I to compare and match them.

    The following snippet displays all the preValues, but currently it doesn't remove any of the preValue options, if none of the selected media items share that preValue.

    If anyone can assist with this, I'd greatly appreciate it:

    <xsl:variable name="businessNames" select="umbraco.library:GetPreValues(1449)" />
                <xsl:for-each select="$businessNames//preValue">
                    <xsl:variable name="businessName" select="umbraco.library:Split($currentPage/downloadFiles, ',')" />
                    <xsl:choose>
                        <xsl:when test="umbraco.library:GetMedia($businessName/value, 0)/business != '.'">
                            <option>
                                <xsl:attribute name="value"><xsl:value-of select="umbraco.library:Replace(., ' ', '-')" /></xsl:attribute>
                                <xsl:value-of select="." />
                            </option>
                        </xsl:when>
                        <xsl:otherwise>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 24, 2014 @ 08:28
    Dennis Aaen
    0

    Hi JV,

    I just have take a look at your code, and I think I have found some issues.

    So how about something like this:

    <xsl:variable name="businessNames" select="umbraco.library:GetPreValues(1449)" />
                <xsl:for-each select="$businessNames//preValue">
                    <xsl:variable name="businessName" select="umbraco.library:Split($currentPage/downloadFiles, ',')" />
                    <xsl:choose>
                        <xsl:when test="umbraco.library:GetMedia($businessName/value, 0)/business !=''">
                            <option>
                                <xsl:attribute name="value"><xsl:value-of select="umbraco.library:Replace(., ' ', '-')" /></xsl:attribute>
                                <xsl:value-of select="." />
                            </option>
                        </xsl:when>
                        <xsl:otherwise>
                &nbsp;
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>

    The first I thing I think went wrong in your code is your check for if busines is empty, and the second thing that I spotted is that you have an empty othervise, and that´s not possible.

    Hope this can helps you one step further,

    /Dennis

  • syn-rg 282 posts 425 karma points
    Mar 26, 2014 @ 00:35
    syn-rg
    0

    Hi Dennis,

    I ended up using a different method, which is much easier: http://our.umbraco.org/forum/developers/xslt/49390-Remove-duplicates-from-for-each-list

    Cheers, JV

Please Sign in or register to post replies

Write your reply to:

Draft