4

I want to display a message after clicking a button in Joomla using:

Joomla.renderMessages({"success":"this is test message"});

enter image description here

but it displays the characters vertically and in descending order, whereas I want to display it like so:

this is test message

How can I achieve this?

5

It expects the messages to be passed in an array, even if there is only a single message, ie

Joomla.renderMessages({"success":["this is test message"]});

The formatting example given in the source code for the renderMessages function (\media\system\js\core-uncompressed.js) is:

var messages = {
     "message": ["Message one", "Message two"],
     "error": ["Error one", "Error two"]
};
1

The above answer is great, below is some code to add a title to the message. As a side note, you can also load other strings & use those to create a custom alert. The title of the string is added to the alerts main class.

Joomla.JText.load({success: "Success", custom_alert: "Custom Alert"});

Joomla.renderMessages({'success': ['This has a title!'], 'custom_alert': ['This has a title!']});

custom message

As you can see above the custom alert has the class alert-custom_alert added.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.