###Select several elements
https://docs.google.com/spreadsheets/d/1H7y_Aoy6pKHUhvXo6EwiYuNKl-7oe9Zyl7mN3QYRIPk/edit?usp=sharing Copy the project here http://goo.gl/LxGXfU Disscussion http://goo.gl/UWi1ee http://www.youtube.com/watch?v=dm4z9l26O0I
###Select several elements
https://docs.google.com/spreadsheets/d/1H7y_Aoy6pKHUhvXo6EwiYuNKl-7oe9Zyl7mN3QYRIPk/edit?usp=sharing Copy the project here http://goo.gl/LxGXfU Disscussion http://goo.gl/UWi1ee http://www.youtube.com/watch?v=dm4z9l26O0I
function onOpen(e) { | |
SpreadsheetApp.getUi() | |
.createMenu('Custom Menu') | |
.addItem('Show dialog', 'showDialog') | |
.addToUi(); | |
} | |
function showDialog() { | |
var html = HtmlService.createTemplateFromFile('Page').evaluate(); | |
SpreadsheetApp.getUi() | |
.showSidebar(html); | |
} | |
var valid = function(){ | |
try{ | |
return SpreadsheetApp.getActiveRange().getDataValidation().getCriteriaValues()[0].getValues(); | |
}catch(e){ | |
return null | |
} | |
} | |
function fillCell(e){ | |
var s = []; | |
for(var i in e){ | |
if(i.substr(0, 2) == 'ch') s.push(e[i]); | |
} | |
if(s.length) SpreadsheetApp.getActiveRange().setValue(s.join(', ')); | |
} |
<div> | |
<? var data = valid(); ?> | |
<form id="form" name="form"> | |
<? if(Object.prototype.toString.call(data) === '[object Array]') { ?> | |
<? for (var i = 0; i < data.length; i++) { ?> | |
<? for (var j = 0; j < data[i].length; j++) { ?> | |
<input type="checkbox" id="ch<?= '' + i + j ?>" name="ch<?= '' + i + j ?>" value="<?= data[i][j] ?>"><?= data[i][j] ?><br> | |
<? } ?> | |
<? } ?> | |
<? } else { ?> | |
<p>May be current cell havn't the <a href="https://support.google.com/drive/answer/139705?hl=en">Data validation...</a></p> | |
<? } ?> | |
<input type="button" value="fill current" onclick="google.script.run.fillCell(this.parentNode)" /> | |
<input type="button" value="get validation from current" onclick="google.script.run.showDialog()" /> | |
</form> | |
</div> |
This really nice!
A couple questions...
1- If I wanted to add an input like "Discard" that effectively closes Page.html the way that the system "X" does in the top right corner, what would I set as the onClick event?
input type="button" value="Discard" onclick="..." />
2- When the ShowDialog is fired, any ideas on how the values already in the cell could be used to pre-check options shown in the Page.html? Let's say that my validation list of values is: blue, red, yellow, green and cell B3 contains "blue,green" when I invoke the Custom Menu / showdialog, I'd want blue and green to be checked and red and yellow to be unchecked.
Thanks!
Nice!