darbeey Posted October 9, 2013 Share Posted October 9, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282845-help-with-adding-disabled-to-a-form-option/ Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2013 Share Posted October 9, 2013 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]); } Quote Link to comment https://forums.phpfreaks.com/topic/282845-help-with-adding-disabled-to-a-form-option/#findComment-1453306 Share on other sites More sharing options...
darbeey Posted October 10, 2013 Author Share Posted October 10, 2013 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/282845-help-with-adding-disabled-to-a-form-option/#findComment-1453440 Share on other sites More sharing options...
darbeey Posted October 11, 2013 Author Share Posted October 11, 2013 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]); Quote Link to comment https://forums.phpfreaks.com/topic/282845-help-with-adding-disabled-to-a-form-option/#findComment-1453590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.