Copied to clipboard

Flag this post as spam?

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


  • Jonathan 8 posts 28 karma points
    Dec 16, 2009 @ 02:04
    Jonathan
    0

    Obtaining the value of items selected in a checkbox list

    I've created a checkbox list based datatype, and I am trying to obtain the value of the selected checkboxes from another content node - I get the text of the selected items, not the value when I try to query it.  I'm not sure what I'm doing wrong.  Code is something like this :

    <xsl:variable name="content" select="umbraco.library:GetXmlNodeById(umbraco.library:RequestQueryString('id'))" />
    <xsl:value-of select="$content/data[@alias='theCBL']" />

    where theCBL is the checkbox list whose set values I am trying to examine.

    The output I get is a comma-separated list of the names of the selected fields. Is there some way to get the values?

    (Using Umbraco 4.0.2.1)

  • Lee 1130 posts 3088 karma points
    Dec 16, 2009 @ 07:27
    Lee
    0

    Can you post the output from using so we can see what you have to play with

    <xsl:variable name="content" select="umbraco.library:GetXmlNodeById(umbraco.library:RequestQueryString('id'))" />

  • Jonathan 8 posts 28 karma points
    Dec 17, 2009 @ 05:48
    Jonathan
    0

    I've changed things around a bit and I'm still getting the same result with just

    <xsl:value-of select="$currentPage/data[@alias='theCBL']" />

    i.e. I see the name, not the ID of the selected items.  (theCBL is a checkbox list attribute of the node)

    The other discussions I've found regarding the use of checkbox lists seem to indicate that values are returned and GetPrevalue() should be used to retrieve the associated name...

  • Thomas Kahn 602 posts 506 karma points
    Jun 04, 2010 @ 11:18
    Thomas Kahn
    0

    Hi!

    I'm having the same problem.

    I have a checkbox list. Retrieving the texts (using XSLT) works fine, but I'd like to retrieve the the values (the numbers). Looking at the XML-content (umbraco.config) the values are not present. It looks like this:

    <data alias="caseCategory"><![CDATA[Webb,Film,DR,Övrig media]]></data>

    So how do I retrieve the values using XSLT? Is it possible with the checkbox list data type?

    The reason I need the values is that I'm using them as parameters in some jQuery/AJAX stuff that I'm doing and when the texts contain special characters like "å.ä.ö" Internet Explorer has trouble parsing them. If I could somehow use the values instead, I wouldn't get this problem. In any case, parsing items based on the text is bad practice.

    I'd be very glad if someone could give me a pointer in the right direction!

    /Thomas Kahn

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 04, 2010 @ 11:47
    Lee Kelleher
    0

    Hi all,

    Thomas is correct, the checkbox list data-type will give you a comma-separated list of values... so to make use of them, I use the "umbraco.library.Split()" method. Like so, with comments:

    <!-- get the id from the querystring -->
    <xsl:variable name="requestId" select="number(umbraco.library:RequestQueryString('id'))" />
    <!-- check that its numeric - and greater than zero -->
    <xsl:if test="$requestId &gt; 0">
        <!-- get the content xml -->
        <xsl:variable name="content" select="umbraco.library:GetXmlNodeById($requestId)" />
        <!-- check if the 'theCBL' has a value -->
        <xsl:if test="string($content/data[@alias='theCBL']) != ''">
            <!-- split the comma-separated values -->
            <xsl:variable name="values" select="umbraco.library:Split($content/data[@alias='theCBL'], ',')" />
            <!-- check that there are values -->
            <xsl:if test="count($values/value) &gt; 0">
                <!-- loop through each of the values -->
                <xsl:for-each select="$values/value">
                    <!-- do whatever you like here -->
                    <xsl:value-of select="." />
                </xsl:for-each>
            </xsl:if>
        </xsl:if>
    </xsl:if>

    There is a more fleshed out version on my blog post about how to use the Ultimate Picker in XSLT.

    Cheers, Lee.

  • Thomas Kahn 602 posts 506 karma points
    Jun 04, 2010 @ 13:44
    Thomas Kahn
    0

    Hi Lee!

    Thanks for the quick reply! Getting all the text of all checked values by splitting on comma is not the problem - I got that part working. What I want to do is get the value (number) in the datatype, not the text.

    In the example above, want to get "19" not "Varumärkesstrategi". The reason is that I'm using this datatype for categorizing client cases and then, using the web interface the web site visitor can dynamically select nodesets. The selection of the visitor is fed back to Umbraco using a querystring. An example:

    http://www.mysite.com/clientCase?caseCategory=Varumärkesstrategi

    ("Varumärkesstrategi" means "Brand strategy" in Swedish).

    In my XSLT I pick up the querystring and use it to get a nodeset with all client case nodes marked with this category, like this:

    <xsl:variable name="caseCategory" >
    <xsl:choose>
    <xsl:when test="(umbraco.library:RequestQueryString('caseCategory') &lt;= 0) or (string(umbraco.library:RequestQueryString('caseCategory')) = '') or (string(umbraco.library:RequestQueryString('caseCategory')) = 'NaN')">Alla</xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RequestQueryString('caseCategory')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="caseNodeSet" select="umbraco.library:GetXmlAll()//node[@nodeTypeAlias = 'clientDoctype']/node[contains(string(data[@alias='caseCategory']), $caseCategory)]"/>

    In the XSLT above I tell umbraco to get me all client case nodes that are marked with the case category "Varumärkesstrategi".

    On top of this I'm using some jQuery/AJAX to load content in portions so this value is also processed through JavaScript sometimes. It's quite a complex solution and hard to explain briefly.

    I have it working in Firefox but as soon as one of the words contain a scandinavian character like "å", "ä" or "ö" Internet Explorer backfires and refuses to recognise the word.

    If I could switch to using the numeric values instead of the texts, I would get rid of this problem. Preserving the integrity of a numeric value is much easier than preserving a string. So I need to somehow get the numeric values of the checkbox list, not the text values. I'm not even sure if this is possible(?)

    Regards,
    Thomas Kahn

  • Thomas Kahn 602 posts 506 karma points
    Jun 04, 2010 @ 13:57
    Thomas Kahn
    0

    My message got all chewed up by the forum publishing system, but I hope you can still puzzle it together(?)

    /Thomas

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 04, 2010 @ 15:52
    Lee Kelleher
    1

    Hi Thomas,

    As far as I am aware, the checkbox list data-type only stores the text value not the numerical ID.  You'd be better using an Ultimate Picker instance (or create a new data-type based on it) and restrict which nodes are listed in its checkbox list.  That will store the node Ids - again as comma-separated values.

    If you need more flexibility over the source nodes, then you could try the Axendo Ultimate Picker XPath data-type instead?

    Good luck, Lee.

  • Thomas Kahn 602 posts 506 karma points
    Jun 04, 2010 @ 19:38
    Thomas Kahn
    0

    Hi Lee!

    Thanks! You confirm my suspicion that the checkbox list doesn't deal with ID's at all. I think I could convert it to a multiple dropdown list, publishing keys and get the ID's that way. Then I'd use umbraco.library:GetPreValueAsString() to get the text values wherever I need to print the text. It's just that the the CTRL+click behavour of the multiple dropdown list is everything but intuitive and this is an obstacle for beginners.

    /Thomas

Please Sign in or register to post replies

Write your reply to:

Draft