Adding Custom Modal Errors In Moodle App

Adding Custom Modal Errors In Moodle App

by Sanat Sharma -
Number of replies: 3

Hi,
I'm developing a plugin for moodle mobile and need to show an error message (and send user to the Dashboard) when a PHP function returns false.

How does one do Modal/Toast Messages in Moodle Mobile? Furthermore, how does one redirect users to pages? Thanks!

Average of ratings: -
In reply to Sanat Sharma

Re: Adding Custom Modal Errors In Moodle App

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Sanat,

your plugin's Javascript code should have access to a service named CoreDomUtilsProvider, and that service has some helper function for modals. E.g. in here you can see a function that the app usually uses to display an error message. You can also interact with the Ionic services directly: AlertController, LoadingController, PopoverController, ...

As for the redirect, you can use the following line to send the user to the Dashboard:

this.CoreLoginHelperProvider.redirect('CoreCoursesDashboardPage');
This line will do the following:

  • If the user is in a tab that isn't the Dashboard tab, the Dashboard tab will be selected and the Dashboard will be reloaded.
  • If the user is in the Dashboard tab, a confirm message will be displayed asking the user if he wants to go back to Dashboard. If he confirms, he'll go back to the Dashboard.
If you don't want the confirm to be displayed, please try this (I haven't tested it though):

if (this.NavController && this.NavController.root == 'CoreCoursesDashboardPage') {
    this.NavController.goToRoot();

} else {
    this.CoreLoginHelperProvider.redirect('CoreCoursesDashboardPage');
}
Cheers,
Dani
In reply to Dani Palou

Re: Adding Custom Modal Errors In Moodle App

by Sanat Sharma -
Thanks Dani I used this successfully some time ago!