Documentation

Messages

Code snippetsDesign guidelines

Summary

Messages are the primary method for providing system feedback in the product user interface. Messages include notifications of various kinds: alerts, confirmations, notices, warnings, info and errors.

Status

API status:general
Included in AUI core?Yes. You do not need to explicitly require the web resource key.
Web resource key:com.atlassian.auiplugin:aui-messages
Experimental since:3.0

Examples

Inserted with HTML

Backup stale

This instance was last backed up on Thursday, 18 September 2011.

Backing up attachments

Attachments will not be backed up. This needs to be done manually.

Destructive operation!

Data import will wipe all existing content - make sure you backup first!

Success!

You have backed up your system to C:/backups/filename.xml.

Backup stale

This instance was last backed up on Thursday, 18 September 2011.

Inserted with JS

Code

There are several message types with different colours and icons. There are two ways to implement messages: using HTML (or Soy to generate the HTML) or using Javascript.

HTML

<div class="aui-message aui-message-error">
    <p class="title">
        <strong>Error!</strong>
    </p>
    <p>And this is just content in a Default message.</p>
</div>

HTML - deprecated markup

<div class="aui-message error">
    <p class="title">
        <span class="aui-icon icon-error"></span>
        <strong>Error!</strong>
    </p>
    <p>And this is just content in a Default message.</p>
</div>

Javascript

Note you should use the JS API if adding Messages with JavaScript, not the compiled-Javascript-Soy API. Although the two seems similar, the JS API is the supported option.

Default context:

AJS.messages.generic({
   title:"This is a title in a Default message.",
   body: "<p> And this is just content in a Default message.</p>"
});

Note if you do not set the context, the element:

<div id="aui-message-bar"></div>

...must exist in your document, otherwise the message will not appear as it has no target location.

It is more common to set the context:

AJS.messages.generic("#context", {
   title:"This is a title in a Default message.",
   body: "<p> And this is just content in a Default message.</p>"
});

Soy

{call aui.message.warning}
    {param title: 'An error occurred - user intervention required!' /}
    {param closeable: 'true' /}
    {param id: 'messageIDattribute' /}
    {param content}
        <p>Some details about the error so the user knows what to do.</p>
    {/param}
{/call}

Options

When adding an HTML message, you must ensure root element (.aui-message) has the desired message class. Calling from Soy or JavaScript wraps this into one call, for convenience.

Note: icon class have been deprecated. The old message classes are also deprecated, now namespaced with aui-message-

Message typeMessage classSoy callJavascript function
Genericaui-message-genericcall aui.message.genericAJS.messages.generic()
Erroraui-message-errorcall aui.message.errorAJS.messages.error()
Warningaui-message-warningcall aui.message.warningAJS.messages.warning()
Successaui-message-successcall aui.message.successAJS.messages.success()
Infoaui-message-infocall aui.message.infoAJS.messages.info()
Hintaui-message-hintcall aui.message.hintAJS.messages.hint()

HTML options

These options are set by adding classes to the root aui-message div.

ClassEffectExample
closeableAdds a Close icon to the message which closes and removes the message when clicked.
<div class="aui-message closeable">...</div>
fadeoutSince 5.1. Makes the message fade away after five seconds. The fadeout will be cancelled if the user interacts with it (hover or focus). Note the fadeout option is best used via JavaScript and should not be used on critical errors and other information the user must be aware of.
<div class="aui-message fadeout">...</div>

Soy options

These options are set by adding params to the Soy call.

ParamEffectDefault
contentRequired. Content to display within the message.n/a
titleContentTitle text of the message.n/a
idID attributen/a
isCloseableBoolean. Set to true, makes the Message closeable.false

JavaScript options

These options are set in the options object when creating a Message with JavaScript:

OptionDescriptionPossible valuesDefault
(context argument)You can override the default context by passing it into the first argument of the messages function. This is the only option set as an argument.A string in the form of an ID selector#aui-message-bar
bodyThe main content of the message.HTMLnone
closeableAdds a control allowing the user to close the message, removing it from the page.booleantrue
idGives your message an ID attribute, useful for selecting the message later.ID string (no hash)none
insertSets the insert point to the start (prepent) or end (append) of the context element. (Option added in AUI 4.2)prepend, appendappend
shadowedToggles the dropshadow on the message box. Usually not changed from default.booleantrue
titleSets the title text of the message.Plain textnone
fadeout(since 5.1) Toggles the fade away on the messagebooleanfalse
delay(since 5.1) Time to wait (in ms) before starting fadeout animation (ignored if fadeout==false)number5000
duration(since 5.1) Fadeout animation duration in milliseconds (ignored if fadeout==false)number500

AJS.messages events

EventDescription
messageCloseDeprecated messageClose. When a message is closed, messageClose is fired before the message is removed from the DOM, including a reference to the DOM element being removed.
aui-message-closemessageClose. When a message is closed, aui-message-close is fired AFTER the element is removed, a reference to the message being removed is included in the event data.
AJS.$(document).on("aui-message-close", function (e,a) {
    AJS.log("message id: " + a.attr("id"));
});