My goal, simply put, is to highlight a cell range on one google sheet (the \'source\') and move it to another, different google sheet document (the \'target\'). The Target has
Closing this question, as I now know HTML needs to be used.
Here's a simple example of a radio dialog:
function radiosOnADialog() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var html='<html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script></head>';
for(var i=0;i<10;i++) {
html+=Utilities.formatString('<br /><input type="radio" name="rgroup" id="%s" value="%s" onChange="getSelected();" />%s','id'+ Number(i+1),'radio' + Number(i+1),' radio' + Number(i+1));
}
html+='<body><br /><input type="button" value="close" onClick="google.script.host.close()" /><div id="msgdiv"></div>';
html+='<script>function getSelected(){ var selected=document.querySelector(\'input[name="rgroup"]:checked\').value;document.getElementById("msgdiv").innerHTML="<br />You selected " + selected + ".<br />";}</script></body></html>';
var ui=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(ui, 'A Radio Dialog');
}
The Dialog:
I was able to use the Google Sheets checkboxes with the below script to create a radio button effect (still looks like a checkbox, but when one checkbox in a given row is checked, it unchecks any other checkbox in that row (columns B-E) that had previously been checked).
My checkboxes are in columns B,C,D,E and I believe (I am learning as I go, so I'm not 100% sure) that is what "for(var i = 2;i<6;i++)" refers to, with Column B=2 and Column E=5 (i.e. <6). In my testing, this meant that in any given row of my spreadsheet, if one checkbox is checked, any checkboxes in columns B-E would be unchecked. This works perfectly for my purposes, as my only checkboxes are in columns B-E, but I did experiment and found that if I added a checkbox in column A, for example, it would cause checkboxes in B-E to be unchecked, but not vice-versa (i.e. checking a box in columns B-E did not uncheck the one in A). This didn't matter for my purposes since I don't need checkboxes anywhere else, so I didn't troubleshoot it, but obviously some additional code would be needed if you don't want this to happen.
function onEdit(evt) {
var range = evt.range;
var val = range.getValue();
var row = range.getRow();
var col = range.getColumn();
// -------------------------------------
// --- Only 1 checkbox per row can be ticked ---
// -------------------------------------
for(var i = 2;i<6;i++){
if(i == col) continue;
if (val) {
SpreadsheetApp.getActiveSheet().getRange(row,i).setValue('FALSE');
}
}}