I am new to electron and I am trying to open a filedialog that lets the user select a specific file using this code:
const {remote} = require("remote");
const {dialog} = require('electron').remote;
function openFileDialog() {
const savePath = dialog.showSaveDialog();
console.log(savePath)
}
However when I try this I get an error in the console saying:
Uncaught TypeError: Cannot read property 'showSaveDialog' of
undefined.
Does anyone know what I am doing wrong?
EDIT:
I am using this piece of code now as it was proposed below:
var remote = require("remote");
var dialog = require('dialog').remote;
function openFileDialog() {
const savePath = dialog.showSaveDialog(null);
console.log(savePath)
}
inside a file named settings.js which I invoke using this code:
<input class="btn btn-dark" type="button" value="Input" onclick="openFileDialog();">
And I import the script using this code:
<script src="./../javascript/settings.js"></script>
I have tried both with and without remote. I still get the same error
This should work if you're using it in the main process, if you want to use it from a renderer process:
const { dialog } = require('electron').remote;
Also, it's better to define the event-handler in the script. Here is a functional example:
<input class="btn btn-dark" type="button" value="Input" id="dialogBtn">
const { dialog } = require('electron').remote;
document.getElementById("dialogBtn").addEventListener("click", openFileDialog);
async function openFileDialog() {
try {
const savePath = await dialog.showSaveDialog(null);
console.log('savePath: ', savePath);
} catch (e) {
console.log('Error:', e);
}
}
I just solved it using these pieces of code. The first problem was that I needed to enable remoteModule enableRemoteModule: true, then that I needed to wait for the DOM to load using this code:
window.onload=function(){
document.getElementById("dialogBtn").addEventListener("click", openFileDialog);
}
Thank you Majed Badawi for the help!
I am not a developper but I working on a way to send automatic mails of information coming for a googlesheet.
here is what I want to do :
1/ get the mail adress of the ligne in the sheet 1
2/ on the sheet 2, we looking for the line where we have this adress
3/ from the sheet 2, construct an array which contain all the information for the line where we find the mail adress
4/ automatically send the mail to me which contain all the information that are in the array we created
I think that I only have a problem in getting the data in the array because I did a test by sending a "Hello world" mail, and it works.
The error is : "ReferenceError: infoRandonneur is not defined (line 8)"
I don't know it doesn't find "infoRandonneur" ...
Here is my 3 function :
function MailProduit(){
var feuille1 = SpreadsheetApp.getActive().getSheetByName('Form Responses 1');
var data_range1 = feuille1.getDataRange();
var dernier_rang1 = data_range1.getLastRow();
for(var ligne=2; ligne<=dernier_rang1;ligne++){
var isFormulaireOk=feuille1.getRange(ligne,1).getValue();
if(isFormulaireOk == "Formulaire OK"){
var mail1 = feuille1.getRange(ligne,13).getValue();
var nom1 = feuille1.getRange(ligne,4).getValue();
var prenom1 = feuille1.getRange(ligne,5).getValue();
envoyerMailProduit(nom1,prenom1,mail1,ligne);
feuille1.getRange(ligne,1).setValue("Mail produit envoyé");
}
}
}
function envoyerMailProduit(nom,prenom,mail,ligne){
var mailRandonneur = mail;
var ligneProduit = ligne;
var info = recupererInfoCommande(mailRandonneur,ligneProduit);
var modele = HtmlService.createTemplateFromFile('ProduitCommande');
var message = modele.evaluate().getContent();
var adressemail = "baptistelautrette#hotmail.fr";
modele.infoRandonneur = info;
MailApp.sendEmail({
to: adressemail,
subject: "Produits à commander pour un randonneur",
htmlBody: message
});
}
function recupererInfoCommande(mailRandonneur,ligneRandonneur)
{
var mailVerif=mailRandonneur;
var ligneVerif = ligneRandonneur;
var feuille2 = SpreadsheetApp.getActive().getSheetByName('Form Responses 2');
var data_range2 = feuille2.getDataRange();
var dernier_rang2 = data_range2.getLastRow();
var valeurs = feuille2.getRange(ligneVerif,6,ligneVerif,26).getValues();
var enregistrement = valeurs[0];
var adressemail = "baptistelautrette#hotmail.fr";
for(var ligne=2; ligne<=dernier_rang2;ligne++){
var mailRecherche = feuille2.getRange(ligne,2).getValue();
if (mailVerif == mailRecherche){
var infoRandonneur =
{
sacH:enregistrement[0],
sockH:enregistrement[1],
tailleSockH: enregistrement[2],
pantalonH:enregistrement[3],
taillePantalonH:enregistrement[4],
ponchoH:enregistrement[5],
taillePonchoH:enregistrement[6],
tshirtH:enregistrement[7],
tailleTshirtH:enregistrement[8],
polaireH:enregistrement[9],
taillePolaireH:enregistrement[10],
casquetteH:enregistrement[11],
batonH:enregistrement[12],
sacF:enregistrement[13],
sockF:enregistrement[14],
tailleSockF: enregistrement[15],
pantalonF:enregistrement[16],
taillePantalonF:enregistrement[17],
ponchoF:enregistrement[18],
taillePonchoF:enregistrement[19],
tshirtF:enregistrement[20],
tailleTshirtF:enregistrement[21],
polaireF:enregistrement[22],
taillePolaireF:enregistrement[23],
casquetteF:enregistrement[24],
batonF:enregistrement[25]
};
return infoRandonneur;
}
}
}
Here is my mail that I want to send :
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p> Hello World </p>
<p> <?= infoRandonneur.sacF ?> </p>
</body>
</html>
For execution, I only launch MailProduit() that has to find if the situation of the hiker ('form OK' for example), then if it's ok, that launch envoyerMailProduit(), that looks on the other sheet to find the ligne where we find the adress of this hiker, get all the data from the line, and send the mail "ProduitCommande".
So, when I don't put infoRandonneur.sacF in the mail, it works, but like that it doesn't ...
If someone could help me, it would be great.
Thanks,
Baptiste L.
I see 3 declaration of functions but I don't see the execution order of them. Can you please update the question with it? In order to know in which line you get the error. Or is it in the email?
You say you're not a developer so maybe you don't know this but, declaring a function does not make it run, you have to CALL a function in order to get it executed.
For example:
function hello_world() {
document.write("Hello world! - I am just plain text");
} // This declares the function
hello_world(); // This calls the function declared previously
EDIT:
So this is not the problem. Try to make some debugging of your code by writing this in a line where the variable should have a value:
document.write("Variable name: " + variable_name); // The text before the actual variable name will help you to not get lost in the output.
// An example with your code:
var info = recupererInfoCommande(mailRandonneur,ligneProduit);
document.write("Info variable: " + info); // This will output the info value at that line.
I suggest you check the variables are arriving to your functions as they are supposed.
I have this script that should work but I am getting the message:
TypeError: Object doesn't support property or method 'push'
I've also tried:
window.push(list);
and this:
var push = document.getElementById('push');
push.addEventListener('click', function() {
var text = prompt('title', '?, curl => ' + 'example.com?callback=?');
push.value = text;
});
I have also tried:
window.push(list);
window.push(prompt("title", "?", "callback=?", "success"), "?,?", ["cat"]);
list.push(text);
and this:
window.push(list);
list.push(text);
Does it mean that I have a typo somewhere in my script code?
<hr>
<p id="push">title,</p>
<p id="request">cat,</p>
I am a student so if I am doing something wrong please let me know.
When I create a new div element, I want the button to perform an onClick event that will capture the ${Title} variable. Then the getTitle(Title) function will take ${Title} as a parameter and use module.exports so that I can use this variable in another javascript file. (the way I use module.exports is through browserify.)
function createDiv(Title){
var div = document.createElement('div');
div.setAttribute('class', `column-photo ${Type} show`);
var newDiv =
`
<div class="content">
<button class="content-text" id="Btn" onClick="getTitle(${Title})">
</button>
</div>
`;
div.innerHTML = newDiv;
document.getElementById('someID').prepend(div);
}
function getTitle(Title){
var imageTitle = Title.value;
module.exports = imageTitle;
console.log(imageTitle);
}
However, the problem here is that it throws an error when I click the button:
(${Title} = 'a' and filename is gallery.html)
Uncaught ReferenceError: 'a' is not defined
at HTMLButtonElement.onclick (gallery.html:1)
The other javascript file will import this variable. However, console.log(imageTitle.imageTitle) is undefined. How do I fix this?
var imageTitle = require('./file.js');
console.log(imageTitle.imageTitle);
When constructing the HTML element, you need to properly inject the function parameter. The error lays in this line:
onClick="getTitle(${Title})"
if the Title is "a", then after building the string, it becomes:
onClick="getTitle(a)"
which produces this error because a is not defined anywhere.
To fix this, change the line to this one:
onClick="getTitle('${Title}')"
which will be properly resolved to:
onClick="getTitle('a')"
I'm trying to use the authorize.net AcceptUI hosted form in a Vue.js component. https://developer.authorize.net/api/reference/features/acceptjs.html#Integrating_the_Hosted_Payment_Information_Form
The button to launch the form and the form show up correctly. After entering some test payment information and hitting submit, the form kind or reloads but doesn't disappear as it should. In the console I get the error AcceptUI.js:1 Uncaught TypeError: window[i] is not a function.
The relevant section of the AcceptUI script is this:
A = function(t) {
"function" == typeof i ? i.call(null, t) : window[i](t)
};
I have a responseHandler function defined. I'm not sure why it's not working. I stripped the code down to be almost identical to the sample that authorize.net provides but I'm assuming something with Vue.js or Typescript is interfering.
Please ignore any unrelated issues with the code. I'm only concerned about getting the responseHandler to work then I'll build out the rest of the functionality.
<template>
<div>
<form id="paymentForm" method="POST">
<button type="button"
class="AcceptUI"
data-billingAddressOptions='{"show":true, "required":false}'
data-apiLoginID="<redacted>"
data-clientKey="<redacted>"
data-acceptUIFormBtnTxt="Submit"
data-acceptUIFormHeaderTxt="Card Information"
data-responseHandler="responseHandler">Pay
</button>
</form>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
#Component
export default class SubscriptionManager extends Vue {
protected responseHandler(response: any) {
console.log(response);
}
protected paymentFormUpdate(opaqueData: any) {
const dataDescriptor: any = document.getElementById("dataDescriptor");
dataDescriptor.value = opaqueData.dataDescriptor;
const dataValue: any = document.getElementById("dataValue")
dataValue.value = opaqueData.dataValue;
// If using your own form to collect the sensitive data from the customer,
// blank out the fields before submitting them to your server.
const cardNumber: any = document.getElementById("cardNumber");
cardNumber.value = "";
const expMonth: any = document.getElementById("expMonth")
expMonth.value = "";
const expYear: any = document.getElementById("expYear")
expYear.value = "";
const cardCode: any = document.getElementById("cardCode")
cardCode.value = "";
const paymentForm: any = document.getElementById("paymentForm")
paymentForm.submit();
}
}
</script>
I just ran into this same problem today. My problem was that the function named in data-responseHandler couldn't be found when it was time to execute the response callback. I had defined data-responseHandler="authnetResponseHandler" but forgot to define function authnetResponseHandler(response) before testing it.
https://developer.authorize.net/api/reference/features/acceptjs.html#Handling_the_Response