Closed Waxter81 closed 6 years ago
Hi,
Instead of hacking the library, you may consider writing your own response plugin.
By doing so, you can register any js function with a command (eg. sweetalert.alert_redirect
), and then invoke this command when the plugin is called in the PHP Response object.
Another option is to extend this library with a new class. See the Adding a new library
section in the Readme file.
Thanks! I will try it.
¿Could you please help me to write my own response plugin outside the vendor folder?
I have write MyPlugin.php extending SweetAlert/Plugin.php. That works fine. But now, I don't know how to write a new alert.js file outside the vendor folder.
The render method in Library Class returns:
return $this->xDialog->render('jaxon::dialogs::' . $sTemplate, array_merge($aLocalVars, $aVars));
Although I overwrite a render method in MyPlugin, and delete 'jaxon::dialogs::' rendering only $sTemplate path, it tries always to render the path in vendor folder:
Warning: include(....\vendor\jaxon-php\jaxon-core\templates\js/myAlert.js.php): failed to open stream: No such file or directory in ...\vendor\jaxon-php\jaxon-core\src\Utils\Template\Renderer.php on line <i>37</i>
To be able to render templates from a given directory, you first need to declare a view namespace.
$this->xDialog->addViewNamespace('sweetalert', $sDirectory);
Then you render a template like this.
$this->xDialog->render('sweetalert::myAlert.js' $aVars);
If you don't have template variables in your js file, you better install it on your server and load it from your HTML code.
Thanks for your help. With your advices, It's working now.
I know these are stupid questions, but I'm newbie and I'm not used to using namespaces.
I need to make an URL redirection after user clicks button in a SweetAlert Success Dialog. Something like this:
With a standard $response->alert() it works fine, but since SweetAlert is async, the script performs redirection before user can see the dialog.
SweetAlert allows callback functions which could help me to get my goal, so I have hacked your code implementing Modal Dialogs in SweetAlert to let me config custom options in dialog. Like this:
/jaxon-dialogs/src/Libraries/SweetAlert/Plugin.php
Then, in /jaxon-dialogs/src/templates/sweetalert/alert.js , in sweetalert.alert registered method, I have a customized option to execute post-JS code after user clicks OK Button.
Finally, in my Jaxon Method, I set this custom option before calling modal dialog:
Are there any easier or cleaner way to perform this?
Thanks!