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 :
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...
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:
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 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 > 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) > 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>
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:
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(?)
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?
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.
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 :
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)
Can you post the output from using so we can see what you have to play with
I've changed things around a bit and I'm still getting the same result with just
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...
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:
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
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:
There is a more fleshed out version on my blog post about how to use the Ultimate Picker in XSLT.
Cheers, Lee.
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:
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
My message got all chewed up by the forum publishing system, but I hope you can still puzzle it together(?)
/Thomas
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.
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
is working on a reply...