0

Here's my conundrum. My component has several elements and in the admin side lists of each element I have a standard "New" button to create a new record for that element. All my lists work bar 1 which happens to be the default list for the component. So if I have a blank list, ie no records showing in the list, I click the New button and nothing happens. If I change the filter to show a list with a status of say Archived (of which I have a couple of records), then the list is not empty as you would expect, and then when I click the new button, the form opens as expected for me to create a new record. Once I save that record, then remove the filter so it just displays published and unpublished records, then the new button works as it should.

Here is a snippet of my View Tmpl file in my addTemplate function.

$toolbar = Toolbar::getInstance('toolbar');

$canDo = ContentHelper::getActions('com_mycomponent','component',0);

ToolbarHelper::title(Text::_('COM_MYCOMPONENT_TITLE_POSITIONS'), 'positions.png');

$toolbar->link('JTOOLBAR_DASHBOARD', 'index.php?option=com_cpanel&view=cpanel&dashboard=mycomponent');

if ($canDo->get('core.create')) {
    $toolbar->addNew('position.add');
}

if ($canDo->get('core.edit.state')) {
    $dropdown = $toolbar->dropdownButton('status-group')
        ->text('JTOOLBAR_CHANGE_STATUS')
        ->toggleSplit(false)
        ->icon('fa fa-ellipsis-h')
        ->buttonClass('btn btn-info')
        ->listCheck(true);

    $childBar = $dropdown->getChildToolbar();
    $childBar->publish('positions.publish')->listCheck(true);
    $childBar->unpublish('positions.unpublish')->listCheck(true);
    $childBar->archive('positions.archive')->listCheck(true);
    $childBar->checkin('positions.checkin')->listCheck(true);

    if ($this->state->get('filter.state') != -2) {
        $childBar->trash('positions.trash')->listCheck(true);
    }
}

As always, any guidance appreciated.

1 Answer 1

1

I found the problem although if anyone can explain why this is the case I would appreciate it. It was because I had an if statement around the table in the template display file as follows:

<form action="<?php echo Route::_('index.php?option=com_mycomponent&view=positions'); ?>" method="post" name="adminForm" id="adminForm">
    <div id="j-main-container" class="j-main-container">

        <?php echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>

        <?php if (empty($this->items)) : ?>
            <div class="alert alert-info">
                <span class="fa fa-info-circle" aria-hidden="true"></span><span class="sr-only"><?php echo Text::_('INFO'); ?></span>
                <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
            </div>
        <?php else : ?>
            <table class="table table-striped" id="positionList">

So once I moved this if statement to be wrapped around the "foreach", then the New button worked fine. As it turns out I don't need this alert display anyway, so I'll be removing it entirely. Cheers.

2
  • It doesn't make a lot of sense that the New button is rendered but is not responsive to being clicked unless it is outside the if section.. I would want to see more code around where the toolbar is rendered and maybe a breakpoint in position->add() to check if it is in fact reaching that method but failing silently.
    – Irata
    Commented Jul 17 at 5:45
  • Hmmm I agree that it doesn't make sense, when I get a moment I'll revisit this to see if I can identify the cause. Commented Jul 27 at 2:20

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.