How to show auto-fade notification on top of the screen?

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
ppfoong
Veteran Member
Posts:94
Joined: 2021-07-13 16:46

How to show auto-fade notification on top of the screen?

Post by ppfoong » 2025-12-06 14:16

I tried to use the function showNotifications, but nothing happened.

I tried to use WindowMessages::addDismissable, the notification shows up, but without the auto-fade effect that I want.

In addition, if I update on the same page for more than one time, the old notification will show up together with the new notification, causing multiple notifications show up at the same time.

My code:

Code: Select all

			$sendResult = sendmail([
				'to' => $recipeint_mail,
				'name' => $recipient,        
				'subject' => '...',        
				'message' => "..."
			]);
			if ($sendResult === true) {
				WindowMessages::addDismissable('Notification email sent to '.$recipient, 'alert alert-success');
			} else {
				WindowMessages::addDismissable('Unable to send notification email to '.$recipient, 'alert alert-danger');
			}


User avatar
lramirez
Veteran Member
Posts:114
Joined: 2019-11-01 23:23

Re: How to show auto-fade notification on top of the screen?

Post by lramirez » 2025-12-07 06:26

Hi... I don't know if this will help, but I applied this and it worked in my project. Try this code in the footer-extras section.

Code: Select all

<script>
    $j(function() {
  // Wait 3 seconds and then fade the messages
           setTimeout(function(){
               $j('.alert-dismissable, .alert.alert-info, .alert.alert-warning, .alert.alert-success').fadeOut(500);
            }, 3000); // 3000 ms = 3 seconds
     });
</script>
Luis Ramirez R.

ppfoong
Veteran Member
Posts:94
Joined: 2021-07-13 16:46

Re: How to show auto-fade notification on top of the screen?

Post by ppfoong » 2025-12-07 09:44

Thanks, it works!

ppfoong
Veteran Member
Posts:94
Joined: 2021-07-13 16:46

Re: How to show auto-fade notification on top of the screen?

Post by ppfoong » 2025-12-07 09:59

Any idea on how to make the faded notification be removed and will not show up again?

My code is placed in table update function.

When I made some changes and save the change, the message appears, good.

When I save the change again on the same page, the message appears 2 times. Expected it to only appear 1 time for the 2nd change.

ppfoong
Veteran Member
Posts:94
Joined: 2021-07-13 16:46

Re: How to show auto-fade notification on top of the screen?

Post by ppfoong » 2025-12-09 15:40

Hmm... there is a side effect with this code.

All the hint text description (the "i" beside the field captions) will not be able to expand and show up.

lramirez wrote: ↑
2025-12-07 06:26
Hi... I don't know if this will help, but I applied this and it worked in my project. Try this code in the footer-extras section.

Code: Select all

<script>
    $j(function() {
  // Wait 3 seconds and then fade the messages
           setTimeout(function(){
               $j('.alert-dismissable, .alert.alert-info, .alert.alert-warning, .alert.alert-success').fadeOut(500);
            }, 3000); // 3000 ms = 3 seconds
     });
</script>

saymaad
AppGini Super Hero
AppGini Super Hero
Posts:131
Joined: 2024-06-03 16:17

Re: How to show auto-fade notification on top of the screen?

Post by saymaad » 2025-12-10 08:37

Hi,

The side effect you've mentioned is because the descriptions use class alert-info and they are also faded out because of the code you shared. Moreover, as you are only fading the elements out, the Window Messages may stack, try replacing your setTimeout function with the code below to fix both the issues:

Code: Select all

$j('.users-area > .alert').each(function(){
    var $el = $j(this);
    setTimeout(function(){
        if(typeof $el.alert === 'function') {
            $el.alert('close');
        } else {
            $el.fadeOut(400, function(){ $j(this).remove(); }); }
        }
    , 3000);
});
regards,
Saymaad

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts:1757
Joined: 2018-04-01 10:12

Re: How to show auto-fade notification on top of the screen?

Post by pbottcher » 2025-12-10 09:58

Hi,

maybe another suggestion.
You could also use the build in Notification::show.

On the table after update put the message you want to display into the $_SESSION variable.
On the detailview (I assume after you save the record, you go back to the detail view) check for that information and display the Notification.

Code could look like:
YOURTABLENAME_after_update:

Code: Select all

			$sendResult = sendmail([
				'to' => $recipeint_mail,
				'name' => $recipient,        
				'subject' => '...',        
				'message' => "..."
			]);
			if ($sendResult === true) {
				$_SESSION['YOURTABLENAME_msg'.$data['selectedID']]='Notification email sent to '.$recipient;
				$_SESSION['YOURTABLENAME_cls'.$data['selectedID']]='success');
			} else {
				$_SESSION['YOURTABLENAME_msg'.$data['selectedID']]='Unable to send notification email to '.$recipient;
				$_SESSION['YOURTABLENAME_cls'.$data['selectedID']]='danger');
			}
YOURTABLENAME_header -> detailview :

Code: Select all

			case 'detailview':
				$header='';
				if (isset($_SESSION['YOURTABLENAME_msg'.$_REQUEST['SelectedID']]) && isset($_SESSION['YOURTABLENAME_cls'.$_REQUEST['SelectedID']])) {
					$header='<%%HEADER%%>'.Notification::show([
					'message' => $_SESSION['YOURTABLENAME_msg'.$_REQUEST['SelectedID']],
					'class' => $_SESSION['YOURTABLENAME_cls'.$_REQUEST['SelectedID']],
					'dismiss_seconds' => 5]);
					unset($_SESSION['YOURTABLENAME_msg'.$_REQUEST['SelectedID']]);
					unset($_SESSION['YOURTABLENAME_cls'.$_REQUEST['SelectedID']]);
				};
				break;
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

ppfoong
Veteran Member
Posts:94
Joined: 2021-07-13 16:46

Re: How to show auto-fade notification on top of the screen?

Post by ppfoong » 2025-12-10 16:41

This works like a charm.

Thanks.

pbottcher wrote: ↑
2025-12-10 09:58
Hi,

maybe another suggestion.
You could also use the build in Notification::show.

On the table after update put the message you want to display into the $_SESSION variable.
On the detailview (I assume after you save the record, you go back to the detail view) check for that information and display the Notification.

Code could look like:
YOURTABLENAME_after_update:

Code: Select all

			$sendResult = sendmail([
				'to' => $recipeint_mail,
				'name' => $recipient,        
				'subject' => '...',        
				'message' => "..."
			]);
			if ($sendResult === true) {
				$_SESSION['YOURTABLENAME_msg'.$data['selectedID']]='Notification email sent to '.$recipient;
				$_SESSION['YOURTABLENAME_cls'.$data['selectedID']]='success');
			} else {
				$_SESSION['YOURTABLENAME_msg'.$data['selectedID']]='Unable to send notification email to '.$recipient;
				$_SESSION['YOURTABLENAME_cls'.$data['selectedID']]='danger');
			}
YOURTABLENAME_header -> detailview :

Code: Select all

			case 'detailview':
				$header='';
				if (isset($_SESSION['YOURTABLENAME_msg'.$_REQUEST['SelectedID']]) && isset($_SESSION['YOURTABLENAME_cls'.$_REQUEST['SelectedID']])) {
					$header='<%%HEADER%%>'.Notification::show([
					'message' => $_SESSION['YOURTABLENAME_msg'.$_REQUEST['SelectedID']],
					'class' => $_SESSION['YOURTABLENAME_cls'.$_REQUEST['SelectedID']],
					'dismiss_seconds' => 5]);
					unset($_SESSION['YOURTABLENAME_msg'.$_REQUEST['SelectedID']]);
					unset($_SESSION['YOURTABLENAME_cls'.$_REQUEST['SelectedID']]);
				};
				break;

Post Reply