Sweetalert2 won't close - aurelia

using
aurelia-cli - 0.30.1
sweetalert2 - 6.6.5
typescript - 2.3.3
latest browsers (FF, Chrome, IE, Opera)
ts code
public showHelp() {
swal('Test').then((out) => {
console.log(out);
}).catch((error) => console.log(error));
}
alert displays with no problems, but clicking on confirm button does not dismis the alert. alert also won't dismiss on outside click. pressing ESC or ENTER works fine.
no errors throw ...
any idea why this will not accept click?
I have put breakpoints on these
// Mouse interactions
var onButtonEvent = function onButtonEvent(event) {
// Closing modal by close button
getCloseButton().onclick = function () {
// Closing modal by overlay click
container.onclick = function (e) {
in swal source, but they never get hit...
also tried setting target to something else than body, with the same result.

I had the exact same issue and apparently this is what was giving me the problem:
.swal2-container:not(.swal2-in) {
pointer-events: none;
}
Just comment that line or change none to all (Although I don't know yet if it breaks anything else)
I'm using:
paper-dashboard (free angular2 version) - 1.0.0
angular.cli - 1.1.1
sweetalert2 - 6.6.6
typescript - 2.3.3
latest browsers (same)

I'm unable to reproduce what you're experiencing. Using sweetalert2 v6.6.6 (oh dear), the alert displays and hides properly on all scenarios you mention: the [OK] button, clicking outside the alert dialog and the keyboard modifiers.
I'm using the configuration below. You're probably already aware, but please do note that I'm explicitly including the css file in the aurelia.json and referencing it in the app.html view.
Here is the full app:
aurelia.json
{
"name": "sweetalert2",
"path": "../node_modules/sweetalert2/dist",
"main": "sweetalert2",
"resources": [
"sweetalert2.css"
]
}
app.ts
import swal from 'sweetalert2';
export class App {
attached() {
this.showHelp();
}
public showHelp() {
swal('Test').then((out) => {
console.log(out);
}).catch((error) => console.log(error));
}
}
app.html
<template>
<require from="sweetalert2/sweetalert2.css"></require>
</template>

Related

The buttons of cookieconsent package not work in vuejs

I have a front in Vue.
I've added the package cookieconsent:
import cookieconsent from "cookieconsent";
Vue.use(cookieconsent);
In App.vue I initialise it:
created() {
this.cookiesConsentInitialise();
},
methods: {
cookiesConsentInitialise() {
window.cookieconsent.initialise({
//...
//settings
//...
});
}
}
The cookie notification is displayed perfectly, but the accept and decline buttons not perform any action, stays on the screen all the time.
I have followed Osano's documentation.
I would suggest to use vue-cookie-law npm package as it is optimised for vue projects and is popular enough.
There is good documentation and it is pretty customisable.

Detect browser (tab) closing or reloading on Vue

I am currently using window.onbeforeunload function on my vue to detect browser's closing or reloading tab to show a like below.
mounted: function () {
window.addEventListener('beforeunload', this.confirmSave)
},
methods: {
confirmSave(event) {
if (this.onChangeMode) {
event.returnValue = 'You have some unsaved changes'
return 'You have some unsaved changes'
}
},
},
It's working perfectly on PC Chrome but not working on iPad (both Safari and Chrome). My iPad version is 14.0.1.
I also tried something else like pagehide but not working either.

Electron + Vue tray wrong icon path

I'm trying to create a Windows applications using Electron and Vue. I want to send the application to the Tray and show an icon to maximize it again when clicked. It works fine in DEV but when I build the app, the Tray icon is not working.
The app it's executing, but when minimized the tray is not showing and there is not option to open it again (need to kill the process).
This is the code I'm trying to use:
app.on("ready", async () => {
if (isDevelopment && !process.env.IS_TEST) {
try {
await installExtension(VUEJS_DEVTOOLS);
} catch (e) {
console.error("Vue Devtools failed to install:", e.toString());
}
}
createWindow();
createTray()
});
const createTray = () => {
const tray = new Tray(resolve(process.resourcesPath, '\\resources\\homeico.ico'))
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show App', click: function () {
app.show()
}
},
{
label: 'Quit', click: function () {
app.isQuiting = true
app.quit()
}
}
])
tray.setToolTip('This is my application.')
tray.setContextMenu(contextMenu)
tray.on('click', () => {
console.log('clicked')
})
}
And in my vue.config.js:
pluginOptions: {
electronBuilder: {
nodeIntegration: true,
builderOptions: {
"extraResources": [
{
"from": "extraResources",
"to": "resources",
"filter": [
"**/*"
]
}
]
}
},
},
The resolve(process.resourcesPath, '\resources\homeico.ico') line is pointing to a existing file, I'm printing this route in the App and I can open it in my Windows Explorer, but when I want to show the Image in the app, I can see next error in the DevTools:
Not allowed to load local resource: file:///C:/Users/mysUser/AppData/Local/Programs/business-config-tool/resources/resources/homeico.ico
The path is accesible, but not in the App.
What's the correct way to configure the path to the icon? there is another path I can configure for assets? I also tried with __dirname and other icon formats (ico, png..)
Thank you.
I ran into the same issue. I searched for a solution for hours, and I finally found one.
This solution is made for app using electron-vue (I personally used this Vue Cli electron plugin). And I tested it on Windows only.
The Tray must be initialised with an icon Path, wich needs be different wether you are running a built version of your app (yarn electron:build), or serving your app (yarn electron:serve).
I am using a function that I called isServeMode, wich basically tells me if I am using the serve mode or the buid mode. Here is what the function looks like :
// utils.js file
const isServeMode = () => {
return process.env.WEBPACK_DEV_SERVER_URL
}
You don't need to create this function, but it might be usefull somewhere else in your app so I suggest you to put it in a file that you can import from anywhere in your app. In my case, I created a utils.js file where I write those functions.
Then, put your tray icon in the public folder, it can not work if you put the icon in the src/assets folder, since we have to access it from the Node environnement and not from Vue. In my case, I put my icon in public/tray/icon.png.
Finally, we can use the electron Tray with Electron vue like this
import { Tray } from "electron"
import path from "path"
import { isServeMode } from "./utils" // Path depends on where you wrote your function
// Some Electron code...
let tray
createTray = () => {
const iconPath = isServeMode()
? path.join(__dirname, "/bundled/tray/icon.png")
: path.join(__dirname, "/tray/icon.png")
tray = new Tray(iconPath)
}
I will soon release a new version of my Unlighter app, wich is an electron-vue app that will include a Tray example. Feel free to take a look at this "real world app example" if you're interested.

How do I display the captcha icon only on certain pages (VUE reCAPTCHA-v3)?

I use this package : https://www.npmjs.com/package/vue-recaptcha-v3
I add on my main.js :
import { VueReCaptcha } from 'vue-recaptcha-v3'
Vue.use(VueReCaptcha, { siteKey: 'xxxxxxx' })
I add this code :
await this.$recaptcha('login').then((token) => {
recaptcha = token
})
to my component to get token from google recapchta
My problem is the captcha icon in the lower right corner appears on all pages
I want it to only appear in certain components
Maybe I must to change this : Vue.use(VueReCaptcha, { siteKey: 'xxxxxxxxxxxxxxxxx' }). Seems it still mounting to Vue.use. I want to mount to a certain component instead of vue root instance
How can I solve this problem?
Update
I try like this :
Vue.use(VueReCaptcha, {
siteKey: 'xxxxxxx',
loaderOptions: {
useRecaptchaNet: true,
autoHideBadge: true
}
})
It hides the badge. I want the badge to still appear. But only on 1 page, the registration page. How can I do it?
I've had the same issue while using the npm package, it's pretty annoying.
At the end of the day, I've decided not to use the package & follow Google's documentation.
This line here :
grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'login'}).then(function(token) {
recaptcha = token
})
Is equivalent to this line here from the npm package :
this.$recaptcha('login').then((token) => {
recaptcha = token
})
You just need to add this line into your < head > for recaptcha to work :
<script src="https://www.google.com/recaptcha/api.js?render=_reCAPTCHA_site_key"></script>
But as soon the script tag is in your < head >, you will be facing the same issue of it showing on every page.
The hack is that you only insert it into the < head > on components that you need.
There are ways to do this but I ended up referencing this.
You can put it in the methods of your component & call the method when the component is loaded.
That way it will only show up on the pages that you need it to.
in main.js set autoHideBadge true:
import { VueReCaptcha } from 'vue-recaptcha-v3'
Vue.use(VueReCaptcha, { siteKey: 'your site key',
loaderOptions:{autoHideBadge: true }})
in every page you want to show the badge you can show the badge in mounted,
for some reasons until a few seconds after mounted event this.$recaptchaInstance is null and you cant use it, so I use a timeout to showing the badge 5 second after page load in mounted.
mounted(){
setTimeout(()=>{
const recaptcha = this.$recaptchaInstance
recaptcha.showBadge()
},5000)
},
when you show it you have to hide it again in the same page.
beforeDestroy() {
const recaptcha = this.$recaptchaInstance
recaptcha.hideBadge()
},
If you are using composition API setup this is what you need:
const reCaptchaIn = useReCaptcha().instance
onMounted(() => {
setTimeout(() => {
reCaptchaIn.value.showBadge()
}, 3000)
})
Just use this code:
const recaptcha = this.$recaptchaInstance
// Hide reCAPTCHA badge:
recaptcha.value.hideBadge()
// Show reCAPTCHA badge:
recaptcha.value.showBadge()
vue-recaptcha-v3 npm
I stumbled upon this incredibly simple answer. It is excellent especially if you wish to hide the badge from all your pages. You can perhaps use scoped css to hide on some pages as well.
.grecaptcha-badge { visibility: hidden; }
You can read the post here

Angular2 Safari Back Button

In the actual Angular2 beta 14 (and before) there seems to be an issue with the back button (when using routing, and several views) on Safari (actually using 9.1): https://github.com/angular/angular/issues/7722
I also experienced this problem, while this works fine e.g. on Chrome.
I'm looking for a workaround until the issue is fixed?
On "angular2": "2.0.0-beta.14"
I had to run the tick inside a zone to get it to work for me.
import {ApplicationRef, <anything else you need>} from 'angular2/core';
import {Router,<anything else you need>} from 'angular2/router';
export class AppComponent {
constructor(private _ref: ApplicationRef, private _router: Router) {
_router.subscribe((value) => {
_ref.zone.run(() => _ref.tick());
});
}
}
There is partial workaround for this bug:
Inject Router and ApplicationRef into Application component
Subscribe for router changes and trigger full component tree check:
router.subscribe((value)=>
{
//todo: check browser UA or any other parameters to detect back button, i.e. if (safari) {}
//trigger change that will invoke init methods
appRef.tick();
});
angular2 - 2.15.8
constructor(private _ref: ApplicationRef, private _router: Router) {
_router.events.subscribe((value) => {
_ref.zone.run(() => _ref.tick());
});
}
Using _router.subscribe is deprecated and will throw Undefined function .subscribe() on _router.