I'm not sure this is possible with XSLT but wanted to check anyway. I have an Umbraco V4 installation and I have a page that lists its child pages and the content of them (it's actually a list of comments but that doesn't really matter). Currently it lists all the child pages but I want the user to be able to filter the comments shown with a dropdown menu (the comment contains a property type called 'commenttype' that I want to filter by). Is this possible using just XSLT or would some sort of user control be required (I don't really have any .net experience so I would prefer if I could do it with XSLT). The XSLT that currently lists the comments is as follows:
Then you'd have a filter in order to pick out only the commenttype you want in xslt in your for-each.
You'd also need to create a dropdown of all the comment types, so if you don't want to hard-code it you'd need something like the following to get a unique list for a dropdown
Sorry for my ignorance but would the first piece of XSLT you mentioned go into the XSLT I already have for listing the comments and the second part (the one for the select box) go into a separate XSLT file?
Yep, the second piece of xslt would probably go in a separate file, depending on where you want the filter to be. I'd put that separately in a macro and just place it where you want your select field to go
For the first piece you'd just alter your for-each like (beware freely typed code following!)
Ok thanks, I have now modified my XSLT with what you said above plus a few corrections :-) Just wondered how I go about creating the postback form for the select control? Will it not cause a problem because the master template contains a form and I thought you couldn't have a form within a form?
Yeh that will be an issue. You could either remove the form surrounding the textarea and apply more 'locally' where it is actually needed, or do something like (in jQuery, again freely typed and untested!)
Thanks for the response, I did try what you said but unfortunately it did work because I have another form on my page that is used to fill in the comment in the first place and what you suggested tries to submit that form when selecting something from the drop down list.
Thanks for the response, I am not that familar with jquery, where exactly would I put the code you suggested and unfortunately i don't know what you mean by doing it in pure javascript or in my preferred library.
This should submit the form the select element is in. Personally I prefer Dan's option - it is cleaner and more pure, but only if you're already got jQuery on the page. Alternatively, you could write some actual javascript code to do what Dan is suggesting (it would just be a lot longer than in jQuery).
Just FYI - jQuery is a javascript library (its very good) - which means it makes doing things in javascript really easy, but adds a significant amount to be downloaded (mitigated in the case of multiple pages or using a shared jQuery resource).
Thanks for the response, maybe I am being a bit dumb but I now have the following which does show a drop down list populated by any comment types I have but when I select one of the comment types from the list nothing happens not even a javascript error.
Hmm. I found this quite interesting, as I can see a few uses of it. There's a major flaw in my earlier code, in which the querystring will keep getting appended to the current page so it's not very usable. Here's a solution I was able to work up (test page at http://allbutlost.com/umbtest/)
In this I only get the first part of the string to post back to, and I've also hidden the select box with css, then shown it again with jquery. This way people without js turned on won't see a useless select box. The test page seems to work fine.
Dan
p.s. I've used text() to get the actual text from the select box. If you want the value change this to val()
Once again, thanks for the response, I have added the code in the post above to my masterpage in the head section and I have the follow code in my drop down XSLT and List Comments XSLT but when I select something from the drop down box nothing happens. Am I missing something?
Now it looks like your xslt which is causing trouble. Could you post what you're using?
One problem I can see is using values like "commenttype=Idea for new system" - the querystring probably won't work with the spaces. You should probably store commentTypes like "ideas" or "suggestions", then try again against the new values. You'd need to insert these one-word commentTypes as values of the select box, then change the jQuery to post back the val() and not the text() as I described a few posts ago)
e.g.
<option value="ideas">Idea for new system</option>
Drop down filter using XSLT
I'm not sure this is possible with XSLT but wanted to check anyway. I have an Umbraco V4 installation and I have a page that lists its child pages and the content of them (it's actually a list of comments but that doesn't really matter). Currently it lists all the child pages but I want the user to be able to filter the comments shown with a dropdown menu (the comment contains a property type called 'commenttype' that I want to filter by). Is this possible using just XSLT or would some sort of user control be required (I don't really have any .net experience so I would prefer if I could do it with XSLT). The XSLT that currently lists the comments is as follows:
I see two options here:
1. xslt: You'd probably need to post back to the page in order to activate some kind of filter for the xslt to act on, like
Then you'd have a filter in order to pick out only the commenttype you want in xslt in your for-each.
You'd also need to create a dropdown of all the comment types, so if you don't want to hard-code it you'd need something like the following to get a unique list for a dropdown
Then just a form around the select posting back to the page (or a little javascript).
2. Javascript: Give each comment a class with the commenttype, show and hide by class with jquery whatever.
I'd probably go for number 1, it depends how many comments you're expecting though
Dan
Sorry for my ignorance but would the first piece of XSLT you mentioned go into the XSLT I already have for listing the comments and the second part (the one for the select box) go into a separate XSLT file?
Yep, the second piece of xslt would probably go in a separate file, depending on where you want the filter to be. I'd put that separately in a macro and just place it where you want your select field to go
For the first piece you'd just alter your for-each like (beware freely typed code following!)
Dan
Ok thanks, I have now modified my XSLT with what you said above plus a few corrections :-)
Just wondered how I go about creating the postback form for the select control? Will it not cause a problem because the master template contains a form and I thought you couldn't have a form within a form?
You are right - you can't have a form within a form. Try this:
That will submit the first form found on the page (should be the only 1 in .NET's model)
Yeh that will be an issue. You could either remove the form surrounding the textarea and apply more 'locally' where it is actually needed, or do something like (in jQuery, again freely typed and untested!)
This could also be done in pure javscript or in your preferred library
Hope this helps,
Dan
Hi Josh,
Thanks for the response, I did try what you said but unfortunately it did work because I have another form on my page that is used to fill in the comment in the first place and what you suggested tries to submit that form when selecting something from the drop down list.
Hi Dan,
Thanks for the response, I am not that familar with jquery, where exactly would I put the code you suggested and unfortunately i don't know what you mean by doing it in pure javascript or in my preferred library.
Something like the following, changing selectClass to your class or id of the select field
Although it (jQuery) does seem like a lot of overhead just to submit a form.
Dan
p.s.
Should be
(still untested though!)
Dan
This should submit the form the select element is in. Personally I prefer Dan's option - it is cleaner and more pure, but only if you're already got jQuery on the page. Alternatively, you could write some actual javascript code to do what Dan is suggesting (it would just be a lot longer than in jQuery).
Just FYI - jQuery is a javascript library (its very good) - which means it makes doing things in javascript really easy, but adds a significant amount to be downloaded (mitigated in the case of multiple pages or using a shared jQuery resource).
Thanks for the response, maybe I am being a bit dumb but I now have the following which does show a drop down list populated by any comment types I have but when I select one of the comment types from the list nothing happens not even a javascript error.
Hmm. I found this quite interesting, as I can see a few uses of it. There's a major flaw in my earlier code, in which the querystring will keep getting appended to the current page so it's not very usable. Here's a solution I was able to work up (test page at http://allbutlost.com/umbtest/)
In this I only get the first part of the string to post back to, and I've also hidden the select box with css, then shown it again with jquery. This way people without js turned on won't see a useless select box. The test page seems to work fine.
Dan
p.s. I've used text() to get the actual text from the select box. If you want the value change this to val()
Once again, thanks for the response, I have added the code in the post above to my masterpage in the head section and I have the follow code in my drop down XSLT and List Comments XSLT but when I select something from the drop down box nothing happens. Am I missing something?
Dropdown XSLT:
List comments XSLT:
Hmm, should work fine... a few Qs
And is there a demo page I can look at?
Dan
Hi Dan,
No the querystring does not get appended.
There are no javascript errors.
You can see the javascript in the source of the page.
Demo page here http://ideas.imprezait.co.uk/test.aspx
Your select doesn't have a class of "comment_type". Add that and try again
Ok thanks, I have added that and now it is appending the URL but it still shows all the comments instead of filtering them.
Cool, now we're getting somewhere!
Now it looks like your xslt which is causing trouble. Could you post what you're using?
One problem I can see is using values like "commenttype=Idea for new system" - the querystring probably won't work with the spaces. You should probably store commentTypes like "ideas" or "suggestions", then try again against the new values. You'd need to insert these one-word commentTypes as values of the select box, then change the jQuery to post back the val() and not the text() as I described a few posts ago)
e.g.
and
Then adjust the xslt accordingly. Feel free to post your xslt again so I can see if it has any potential problems.
Dan
is working on a reply...