Add custom confirm message to standard joomla 3.0 admin toolbar button
Asked Answered
D

2

11

Add custom confirm message to standard Joomla 3.0 admin toolbar button.

I can get alert messages on delete when I don't select any check boxes on the detailed list.

I can get same on any button by set last parameter true in

JToolBarHelper::custom('userdetails.sendMail', 'mail.png', 'mail_f2.png', 'Send Mail', false);

I want to add a confirm message on the click event of this Button.

Disrepute answered 11/8, 2014 at 12:39 Comment(1)
possible duplicate of Joomla custom toolbar button messageCommunalize
G
3

On view file (tpl/view file name).

<script type="text/javascript">
    Joomla.submitbutton = function(task)
    {
        if (task == 'userdetails.sendMail')
        {
            if (confirm(Joomla.JText._('Do you really want to send mails to selected users?'))) {
                Joomla.submitform(task);
            } else {
                return false;
            }
        }
    }
</script>
G answered 15/6, 2015 at 5:50 Comment(0)
P
0

Just as an addition to Suman Singh's answer, you may want to include the script in the document header, and also be able to translate the confirmation text. So, in your layout file, you can write:

$document = JFactory::getDocument();
$document->addScriptDeclaration('
  Joomla.submitbutton = function(task) {
    if (task == "userdetails.sendMail") {
      if (confirm(Joomla.JText._("COM_YOURCOMPONENT_USERDETAILS_SENDMAIL_CONFIRMATION_TEXT"))) {
        Joomla.submitform(task);
      } else {
        return false;
      }
    }
  }
');
JText::script('COM_YOURCOMPONENT_USERDETAILS_SENDMAIL_CONFIRMATION_TEXT');

And of course in the language/en-GB/en-GB.com_yourcomponent.ini file:

COM_YOURCOMPONENT_USERDETAILS_SENDMAIL_CONFIRMATION_TEXT="Are you sure you want to send mails to the selected users?"
Psilocybin answered 1/10, 2020 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.