Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Filtering categories based on the chosen section (back end)
Try .val()
instead of .text()
. Unless your section titles exactly match your category names, they won’t match. That’s what the plugin I posted above does and it works.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Filtering categories based on the chosen section (back end)
Bloke wrote #279677:
Thanks! Once released, this will allow for
if (@txpinterface == 'admin') {
register_callback('abc_cat_filter','article');
}
function abc_cat_filter() {
echo n.script_js('$(function() {
var cats = $("#category-1"), catsClone = cats.clone().removeAttr("id");
$("#section").change(function() {
var selected = $(":selected", this).val();
cats.empty().append(catsClone.children("option[value=\'\']").clone());
if(selected) catsClone.children("option[value=\'"+selected+"\']").each(function(){
$(this).nextUntil("[data-level=\'"+$(this).attr("data-level")+"\']").clone().appendTo(cats);
});
}).change();
});');
}
Edit: and replacing "#category-1"
with "#category-2"
and "#section"
with "#category-1"
, will restrict Category 2 choices to the children of Category 1.
Edit: replaced hide()
with clone()
, to satisfy all browsers.
Last edited by etc (2014-03-13 14:31:14)
Offline
#15 2014-03-12 14:52:22
- a7aylor
- New Member
- From: Manchester, UK
- Registered: 2014-03-11
- Posts: 9
Re: Filtering categories based on the chosen section (back end)
Bloke wrote #279688:
in case you only want the filtering to take place on certain sections.
That would be ace, thanks.
Amateur plugin question (current experience is paste and click upload :-) – How do I get your PHP code as a BASE64-encoded piece of text to paste in on the plugin page?
Offline
Re: Filtering categories based on the chosen section (back end)
a7aylor wrote #279690:
Amateur plugin question (current experience is paste and click upload :-) – How do I get your PHP code as a BASE64-encoded piece of text to paste in on the plugin page?
Plugin Composer is the easiest option.
Offline
#17 2014-03-12 15:08:04
- a7aylor
- New Member
- From: Manchester, UK
- Registered: 2014-03-11
- Posts: 9
Re: Filtering categories based on the chosen section (back end)
Bloke wrote #279688:
Try
.val()
instead of.text()
. Unless your section titles exactly match your category names, they won’t match. That’s what the plugin I posted above does and it works.
No joy. The match is with the names, not the titles.
Offline
Re: Filtering categories based on the chosen section (back end)
a7aylor wrote #279692:
No joy. The match is with the names, not the titles.
Hmm. Take a look at the page’s HTML source code and check the <option>
value
attributes. The aim is to match the category with the section somehow, bearing in mind Txp will sanitize both section and catgeory titles because they form part of the URL. So, for example, “Human Sciences” would become “human-sciences” in both cases.
The .val()
gets the option value names whereas .text()
gets the (screen-visible) title of the option so you may need to mix and match them to get the desired outcome depending on how you’ve set them up.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#19 2014-03-12 15:35:40
- a7aylor
- New Member
- From: Manchester, UK
- Registered: 2014-03-11
- Posts: 9
Re: Filtering categories based on the chosen section (back end)
Ok so, heres the sections…
<option value="biology">biology</option>
<option value="chemistry">chemistry</option>
<option value="french">french</option>
<option value="ict">ict</option>
<option value="inclusion">inclusion</option>
<option value="physics">physics</option>
<option value="spanish">spanish</option>
<option value="test">test</option>
Heres are some of the categories…
<option value="biology">Biology</option>
<option value="b1">  B1</option>
<option value="b2">  B2</option>
<option value="b3">  B3</option>
<option value="biology-keywords">  Keywords</option>
<option value="isa">  ISA</option>
<option value="chemistry">Chemistry</option>
<option value="c1">  C1</option>
<option value="c2">  C2</option>
<option value="c3">  C3</option>
<option value="chemistry-keywords">  Keywords</option>
Option value does match e.g. biology in sections is also biology(parent) in categories
{Edited to add Textile’s bc. for readability. – Uli}
Last edited by uli (2014-03-12 16:07:16)
Offline
Re: Filtering categories based on the chosen section (back end)
Waou!
How to a member problem become a plugin. Great community !
I’m just a question to bloke and etc plugin code :
Wath the difference since
echo script_js(<<<EOJS
Your JS code
EOJS);
and
echo n.script_js('Js code');
to inject JS code into a page ?
Offline
#21 2014-03-12 16:30:20
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Filtering categories based on the chosen section (back end)
From the browsers I tried, the JS only worked on FF (27 Mac). Failed on Chromium, SAF & OP. Unfortunately I can’t help with that sort of troubleshooting.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Filtering categories based on the chosen section (back end)
Hohooo,
display:none
don’t work for Chrome and IE for option
.
This work only with Firefox…
stackoverflow.com/questions/9234830/how-to-hide-a-option-in-a-select-menu-with-css
Last edited by sacripant (2014-03-12 17:14:46)
Offline
Re: Filtering categories based on the chosen section (back end)
sacripant wrote #279696:
Waou!
How to a member problem become a plugin. Great community !
You said it, I remembered it but I don’t know if it still works: bot_write_tab_customize
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Offline