I have a button and I would like to replace it with other HTML object loaded by google app script via method HtmlService.createTemplateFromFile('HTML_file').
The button onclick function is written in javascript in .html file:
<div id="add_form_button_wraper">
<input type="button" id="add_form" onclick="addForm()" value="Add Form">
</div>
<script>
function addForm() {
innerHTML = google.script.run.getForm(some_args);
document.getElementById("add_form_button_wraper").innerHTML =
innerHTML;
}
</script>
The Code.gs code looks following:
getForm(arg1, arg2) {
// Creating HTML template from html file.
var template = HtmlService.createTemplateFromFile(HTML_TEMPLATE);
template.arg1 = arg1;
template.arg2 = arg2;
return template.evaluate().getContent();
}
After clicking the button the content of the div is changed to undefined. I tried also HTMLService.createTemplateFromFile().getCode() with the same effect.
How to insert into div the raw html code obtained from app script HTMLService?
A Simple Web App Example
Here's how I do my dialogs and web apps. I know it doesn't necessarily pertain to your particular situation but hopefully a working example can give you some ideas as to how you can proceed.
This is a simple example of a standard web app form. You can view it as a dialog or run it as a webapp. It stores all of the response on a sheet.
Code.gs:
Cycling Survey.html: