Jump to content

Recommended Posts

Hello,

 

I am using a component for joomla 2.5 but i hit snag where it comes to selecting the categories from a drop down box in the front end. I want to use  the disabled element for the top category options so that  they are visible but unselectable. Something like this:

 

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_option_disabled

 

The component uses the following code to hide certain categories of my choosing but i don't want to hide them i just want to add the HTML element "disabled" to the corresponding options:

$options = JHTML::_('category.options','com_content',array('filter.published' => 1 ));

        require_once(JPATH_COMPONENT_SITE.DS.'config'.DS.'restrictions.php');
        $myGroups = $acl->getGroupsByUser($my->id,false);        

        foreach($myGroups as $gid) {
            if(isset($groupRestrictions[$gid])) {
                foreach($options as $k=>$option) {
                    if(in_array( $option->value, $groupRestrictions[$gid] )) {
                        unset($options[$k]);
                    }
                }
            }
        }

        $opt = array('value'=>0,'text'=>JText::_('JOPTION_SELECT_CATEGORY'));
        array_unshift($options,$opt);

        return JHTML::_('select.genericlist',$options,'catid',"class='inputbox'",'value','text',$categoryId);
    }

Any help is gratefully appreciated.

Somewhere in the $options array there is a disabled flag for each option. You need to set it to true

 

This code is loop through all the configurable settings for each option in the list

                foreach($options as $k=>$option) {
                    if(in_array( $option->value, $groupRestrictions[$gid] )) {
                        unset($options[$k]);
                    }
                }

it is removing options, which are restricted. maybe change unset($options[$k]); to

if($k == 'disable') {
    $options[$k] = true;  // set the disable setting to true
} else {
    unset($options[$k]);
}

thanks for your answer but it didn't work for me, it made the first category turn into a 1. I think i have narrowed it down a bit but i am having trouble trying to add the disabled="disabled" attribute to the restricted <option>

foreach($options as $k=>$option) {
                    if(in_array( $option->value, $option->title, $groupRestrictions[$gid] )) {
                        $options[$k] = JHTML::_('select.option','disabled="disabled"',$option->value,$option->title);
                    }
                }

Really appreciate your help @Ch0cu3r because you helped me solve the problem with your example. Thanks be to God it is working now using the following code:

$options[$k] = JHTML::_('select.option',$option->value,$option->text,array('disable' => true))

Instead of:

unset($options[$k]);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.