Ad

October CMS | How To Turn Off Flash Messages Or Alerts

- 1 answer

On my application I need to throw some erros, so following the documentation I can throw some errors with custom messages and/or render some partial by using the following code:

throw new AjaxException([
     '#error_box' => Lang::get('xxx.xxxx::lang.frontend.error_ajax_und')
]);

The problem is that I see flash messages with "Default text" and I don't know how to turn it off...

enter image description here

debug mode is disabled

october build: 419

Ad

Answer

In theory you could hook into the ajaxSetup event to disable flash error handling: http://octobercms.com/docs/ajax/javascript-api#global-events-examples

Something along the lines of:

$(document).on('ajaxSetup', function(event, context) {
    // Disable AJAX handling of Flash messages on all AJAX requests
    context.options.flash = false
})

or

$(document).on('ajaxSetup', function(event, context) {
    // Handle Error Messages with a custom handler
    context.options.handleErrorMessage = function(message) {
        // do stuff
    }

    // Handle Flash Messages with a custom handler
    context.options.handleFlashMessage = function(message, type) {
        // do stuff
    }
})
Ad
source: stackoverflow.com
Ad