I'm trying to improve some stuff in a Spreadsheet and for that, I need to use html file (index1.html) to take informations from the user in a form. All the info are used in my gs file (file.gs) with function itemAdd(form)
.
Everything is working but then I try to make a new form for another problem in another html file (index2.html). Using the same technique, all the info are used in function itemAdd(form)
and here is the problem.
The gs file can't differentiate the 2 itemAdd when I want to use the first html file or the second... that's normal because I have 2 functions with the same name (itemAdd(form)
), my problem is how to do 2 different functions knowing that I can't change itemAdd
and form name! I tried to split into 2 different gs files but I read that Google is compiling all the gs file into one so that was not working. I also try to change the form with form2 for index 2 but not working... I guess the solution is somewhere in the html file and it's over my skills in html.
To try to make you understand as much as I can, here is a simplify example of my problem :
Code.gs
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('Form 1')
.addItem('Get info 1', 'test1')
.addToUi();
SpreadsheetApp.getUi()
.createMenu('Form 2')
.addItem('Get info 2', 'test2')
.addToUi();
}
function test1() {
var html = HtmlService.createHtmlOutputFromFile('index1.html')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Give the infos);
}
}
function itemAdd(form) {
//all the things I want to do with the infos given
with the form in index 1
}
function test2() {
var html = HtmlService.createHtmlOutputFromFile('index2.html')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Give the infos);
}
}
function itemAdd(form) {
//all the things I want to do with the infos given
with the form in index 2
}
index1.html
<html>
<head>
<base target="_top" >
</head>
<form>
Info 1 :
<input type="text" name="i1">
<br><br>
Info 2 :
<input type="text" name="i2">
<br>
<input type="button" value="Ajouter"
onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
</html>
index2.html
<html>
<head>
<base target="_top" >
</head>
<form>
Info 3 :
<input type="text" name="i3">
<br><br>
Info 4 :
<input type="text" name="i4">
<br>
<input type="button" value="Ajouter"
onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
</html>