Flash message does not disappear in frontend from

I have a frontend form in a component like this:

{{ form_ajax('onCreateEntry', { novalidate: 1, 'data-request-flash': 1, class: 'form-elements form-horizontal', role: 'form' }) }}

    <div class="form-group text-field span-left">
        <label for="name">Name</label>
        <input type="text" id="name" name="name" class="form-control" />
    </div>

{{ form_close() }}

In the component class I valide like this:

$data = \Input::post();

$rules = [
    'name' => 'required|string',
];

$validation = \Validator::make($data, $rules);
if ($validation->fails()) {
    throw new \ValidationException($validation);
}

I throws a perfect flash message, but the flash doesn’t disappear again.

I included the frameworks extras in my layout above the closing body like this:

{% framework extras %}

The flash message should disappear after a few seconds, or you can close it with the X.

I checked the JS in: /modules/system/assets/js/framework-extras.js

And I don’t get these three lines (309 - 311):

if (type !== 'error') {
    timer = window.setTimeout(remove, interval * 1000);
} // Remove logic

Should it be like that, that an error message doesn’t disappear automatically?

When I set the class to success or info, the flash disappears after some seconds.

UPDATE:
Could we change the code in something like this?

if (interval && interval !== 0) {
        timer = window.setTimeout(remove, interval * 1000);
} // Remove logic

Then we would have control over disappearing or not.

Would it help, if I’d make a PR?

@daftspunky I also noticed that the flash (in case of error) does not dissapear automatically. This creates some confussion in the end user, because when the final green success flash message dissapears, you see like there where another error (when in fact it’s the previous one).

@federico.schafer, @maki3000

This has been addressed in v3.2 - a timer is used again for error flashes

Previously error would have no timer so the error message can be captured. This has been replaced with logic that cancels the timer if the flash message is clicked (i.e when copying the error), this preserves the error message with equivalent UX as before.

1 Like