Disable tootlbar button based on record field value

9 views
Skip to first unread message

GhiaMar

unread,
Jul 25, 2022, 9:33:53 AMJul 25
to Joomla! General Development
Hi! I need a toolbar button disabled based on DB record value, in my case, if DB record send === 1, then the send button must be disabled, is that possible? I'm creating the send toolbar button like this

if ($canDo->get('core.create') && $canDo->get('core.edit'))
{
ToolbarHelper::custom('message.send', 'envelope', '', 'COM_MANAGER_MESSAGE_SEND', false);
}
shot.png

MarkRS

unread,
Jul 25, 2022, 10:30:11 AMJul 25
to Joomla! General Development
Yes (of course) you can do it. If nothing else, look at the way the search filters mechanism works with selecting rows.

Having said that, you can do it with XML within the search options, so perhaps you can refer to a variable that *isn't* in that xml... I haven't tried that but it might work :)

GhiaMar

unread,
Jul 25, 2022, 10:35:56 AMJul 25
to Joomla! General Development
Hi @MarkRS! thanks for the tip, but in my case the send button is in the edit view, not in the data list...

GhiaMar

unread,
Jul 25, 2022, 10:58:05 AMJul 25
to Joomla! General Development
Well, thanks @MarkRS!, reviewing joomla code, found this way to set a toolbar button disabled

$attributes = !empty($this->item->message_sent) ? ['disabled' => 'disabled'] : [];

$toolbar->standardButton('envelope')
->task('message.send')
->attributes($attributes)
->buttonClass('btn btn-primary')
->text('COM_MANAGER_MESSAGE_SEND')
->listCheck(false);

GhiaMar

unread,
Jul 25, 2022, 10:59:42 AMJul 25
to Joomla! General Development
Forgot to mention, got the toolbar like this

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

Reply all
Reply to author
Forward
0 new messages