简体   繁体   中英

how to combine google app script processForm, withSuccessHandler and withUserObject

So I'm following the documentation here:

https://developers.google.com/apps-script/html_service?hl=en#GoogleScriptAPI

and it seems like I should be able to use processForm, withSuccessHandler and withUserObject in the same place, but I can't get it to work at the moment. Here's one attempt

<input name='submission'>
<input type='hidden' name='match' value ='<?= match?>'>
<input type='hidden' name='week' value ='<?= j?>'>
<input type='hidden' name='assignment' value ='<?= i?>'>
<input id='button' type='button' onclick='google.script.run.processForm(this.parentNode).withSuccessHandler(submissionReceived).withUserObject(this).getCurrentDate()'>

but this gives me the following error when the button is clicked:

Cannot read property 'withSuccessHandler_m___' of undefined

The following does work:

google.script.run.withSuccessHandler(submissionReceived).processForm(this.parentNode)

however I want the "submissionReceived" function to receive the local object so that I can make some local changes to reflect the fact that this particular button (of many) has been clicked. Basically this ordering:

google.script.run.processForm(this.parentNode).withSuccessHandler(submissionReceived)

fails with the same "Cannot read property 'withSuccessHandler_m___' of undefined " error, whether or not I am trying to pass an object to submissionReceived

The following will run:

google.script.run.withSuccessHandler(submissionReceived).withUserObject(this).processForm(this.parentNode)

but the single parameter that gets passed to submissionReceived is undefined

Any ideas about how to combine these three functions successfully in order to pass objects to the client side javascript functions on button clicks?

I managed to get this to work with the following:

var r = google.script.run.withSuccessHandler(submissionReceived).withUserObject(this);r.processForm(this.parentNode); 

Seems like the successhandler needs to be set up first. Also note that this passes two parameters to the submissionReceived function, the first of which is undefined and the second of which is the current local object, so the function definition is like this:

function submissionReceived(a,input) {

where a is undefinfed and input is the dom node corresponding to the input tag in which the script runs

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