11

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

I can get alert messages on delete when I don't selected any check boxes on 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?

Jonny C
  • 1,943
  • 3
  • 20
  • 36
Chintan Thummar
  • 1,462
  • 19
  • 32
  • 2
    possible duplicate of [Joomla custom toolbar button message](http://stackoverflow.com/questions/21682391/joomla-custom-toolbar-button-message) – doovers Dec 22 '14 at 03:49

2 Answers2

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>
Suman Singh
  • 1,379
  • 12
  • 20
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?"
mavrosxristoforos
  • 3,573
  • 2
  • 25
  • 40