简体   繁体   中英

Google Sheets Script Sidebar button not activating function

I've spent hours trying to figure this out, since I feel like I should do that before asking a question here. Searched, looked at answers, tried stuff. I think I learn that way and expand my skills/knowledge.

At any rate, I'm trying to just get started using a sidebar to make my sheets script app work better, and testing in small pieces. I want the Clear Old button (at this point) to simply open an alert box with the date in it, fed from a text box generated by datePicker .

Here is the HTML:

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $( function() { $( "#datepicker" ).datepicker(); } ); </script> <base target="_top"> </head> <body> <p><strong>Clear Old Entries</strong></p> <p>Clear Entries before</p> <p><input type="text" id="datepicker"></p> <p><input type="submit" value="Clear Old" onClick="google.script.run.ClearOld(document.getElementById(datepicker).value)" /></p> <p><input type="button" value="Close Sidebar" onClick="google.script.host.close()" /></p> </body> </html> 

And here is the script code that gets the menu item and the sidebar, as well as the function I'm trying to use as a short term test:

 function onInstall(e) { onOpen(e); } function onOpen(e) { SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .createMenu('Bulletinator') .addItem('Create Bulletin', 'bulletinatorSidebar') .addItem('Clear Old', 'clearOldSideBar') .addToUi(); } function bulletinatorSidebar() { var html = HtmlService.createHtmlOutputFromFile('BullV2Side') .setTitle('Bulletinator') .setWidth(300); SpreadsheetApp.getUi().showSidebar(html); } function clearOldSideBar() { var html = HtmlService.createHtmlOutputFromFile('ClearOldSide') .setTitle('Clear Old Entries') .setWidth(300); SpreadsheetApp.getUi().showSidebar(html); } var today; var todayDay; var todayDate; var ui = SpreadsheetApp.getUi(); var sh = SpreadsheetApp.getActiveSheet(); var rg = sh.getDataRange(); var vA = rg.getValues(); var rowsFound = 0; var rowsDeleted = 0; function ClearOld(value) { var clearDate=value; var testThis = ui.alert( 'Clear entries prior to', clearDate, ui.ButtonSet.YES_NO); 

When I click the button in the sidebar there is no response, and nothing shows up in the execution transcript.

On a side note, I also struggled with being able to have two datePickers in the sidebar; only one worked. So that is why this setup has two separate sidebars getting called.

Thanks for any help.

It seems, the datepicker variable is not defined. you have to use the next code

onClick="google.script.run.ClearOld(document.getElementById('datepicker').value)"

or

onClick="google.script.run.ClearOld($('#datepicker').val())"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM