2

While adapting a Joomla!2.5 backend-only component to Joomla!3.3, I've ran into the issue of the toolbar in the data edition page not working at all. Only two buttons were declared: Save and Cancel; neither do anything. Upon first glance, the problem is neither on the view.html.php file, nor tmpl/edit.php. This very component is already being used in our current Joomla!2.5 website and works perfectly.

All control, model and view pages have already been updated to JControllerLegacy, JModelLegacy and JViewLegacy respectively, where applicable. Server settings' error reporting has already been set to Maximum, but there's no error or warning showing.

view.html.php

defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.viewlegacy');

class MrCarrosselNoticiasViewMrCarrosselNoticias extends JViewLegacy {
    function display($tpl = null){
        $form = $this->get('Form');
        $item = $this->get('Item');
        if (count($errors = $this->get('Errors'))){
            JError::raiseError(500, implode('<br />', $errors));
            return false;
        }
        $this->form = $form;
        $this->item = $item;
        $this->addToolBar();
        parent::display($tpl);
    }

    protected function addToolBar(){
        $input = JFactory::getApplication()->input;
        $input->set('hidemainmenu', true);
        $isNew = ($this->item->cod_destaque == 0);
        JToolBarHelper::title($isNew ? "Novo Destaque" : "Editando Destaque");
        JToolBarHelper::save('mrcarrosselnoticias.save');
        JToolBarHelper::cancel('mrcarrosselnoticias.cancel', 'JTOOLBAR_CANCEL');
    }
}

tmpl/edit.php

<?php
defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.modal');
?>

<form action="<?php echo JRoute::_('index.php?option=com_mrcarrosselnoticias&layout=edit&cod_destaque='.(int) $this->item->cod_destaque); ?>" method="post" name="adminForm" id="mrcarrosselnoticias-form">
    <div class="form-horizontal">
        <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>
        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', 'Detalhes do Destaque'); ?>
        <div class="row-fluid">
            <div class="span9">
                <?php echo $this->form->getControlGroup('imagem'); ?>
                <?php echo $this->form->getControlGroup('titulo'); ?>
                <?php echo $this->form->getControlGroup('desc'); ?>
                <?php echo $this->form->getControlGroup('link'); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>
        <?php echo JHtml::_('bootstrap.endTabSet'); ?>
    </div>

<div>
    <input type="hidden" name="task" value="mrcarrosselnoticias.edit" />
    <?php echo JHtml::_('form.token'); ?>
</div>
</form>
3
  • 2
    Since you are asking for help to fix a problem rather than a code review, I have migrated the question to the Joomla! site. Commented Nov 24, 2014 at 19:36
  • Did you check the browser console for any errors? Can you post your edit.php? Commented Nov 25, 2014 at 1:18
  • edit.php added to main post. Also, yes, checked console... Nothing out of the ordinary. Commented Nov 25, 2014 at 15:09

1 Answer 1

1

I've run into this scenario when troubleshooting back-end component functionality. 9 times out of 10 its because I didn't include the JavaScript logic to handle the toolbar tasks. Try adding the below script above the form. Once added, the toolbar call to action buttons should start working.

<script type="text/javascript">
    Joomla.submitbutton = function(task)
    {
        if (task == 'mrcarrosselnoticias.cancel' || document.formvalidator.isValid(document.id('mrcarrosselnoticias-form'))) {
            Joomla.submitform(task, document.getElementById('mrcarrosselnoticias-form'));
        }
    }
</script>

Hope this helps!

1
  • Glad I could help! Commented Nov 26, 2014 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.