Keyword

Edit itemform to send item to one category

More
11 years 3 weeks ago - 11 years 3 weeks ago #118063 by Iwo
Hi.

I have one problem with customizing k2 template:
how to edit template (itemform, I think) to show user exactly ONE category, or maybe subcategories too,
without see other categories?!

Eg. solution with
option[disabled='disabled'] { display: none; }

is not good for me.

Also this can't be resolved with user groups, just to say that.

I have just basic knowledge about PHP, but I suppose that string in itemform.php:
<?php echo $this->lists['categories'];>

should be changed. And, of course, something else! :blink:

Thanks in advance.

Please Log in or Create an account to join the conversation.

More
11 years 3 weeks ago - 11 years 3 weeks ago #118064 by Iwo
Ok, to reply to myself:

Finally, I decided to not to do this with PHP but with JS instead.

So here is code which is works perfectly for me:
<script>
window.onload = function() {
                                                                                
   var fastInternet = document.getElementById("catid");
    for ( var i = 0; i < fastInternet.options.length; i++) {
        var value = fastInternet.options[i].value;
        if(value != '149' && value != '150' && value != '151'){
            //need to hide this
            fastInternet.options[i].setAttribute("disabled", "disabled");
        } 
         //if you need it
        else if(value == 'myValue' || value == 'myValue'){
            fastInternet.options[i].setAttribute("disabled", "disabled");
        }
    }
//hide disabled fo IE
$K2('#catid option[disabled="disabled"]').remove();
};

Where:

fastInternet = just variable
catid = name of "select" tag, eg. in K2 "<select name="catid" id="catid">"
149,150,151 = id's of categories which I WANT to use

"$K2('#catid option[disabled="disabled"]').remove();" = hide disabled options in IE,it works without this for FF

With combination of Comparison Operators (eg. instead != you can use ==) you can get probably situation which is what you want.

This JS code is not mine (I wish I know JS that much! ;) ) , it is from here: JS code source

Line for IE I picked up somewhere on this forum.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum