I'm using Google closure on top of ClojureScript, what is the way to get a value from a "select" in a html element?
I'm trying :
(.value (gdom/getElement "select-combo"))
but I'm getting:
Uncaught TypeError: goog.dom.getElement(...).value is not a function
I also tried "getValue" but no luck so far. I can't find the function in Google API docs either.
Using jQuery it should be:
$("#select-combo").val();
Checkout the ClojureScript CheatSheet
You can get a value natively
(.-innerHTML el)
Or using cljs-oops library:
(oget el "innerHTML")
Related
I'm getting started with Google Apps scripting, and find the autocomplete very useful. However, once you are inside a new function, autocomplete doesn't seem to have any way of knowing what the type is for the parameter. I've seen some answers about python ideas that say that using javadoc will work. But I'm not able to figure it out. Any suggestions?
function myfunc1(){
var activeSheet=SpreadsheetApp.getActiveSheet();
activeSheet//.autocomplete works here
myfunc2(activeSheet)
}
function myfunc2(myActiveSheet){
myActiveSheet//.autocomplete doesn't work here
}
There are limitations to what the UI can do in terms of autocomplete.
Usually I just keep the reference documentation open in another tab and refer to that, but you can also trick the UI into auto completing using comments:
function myfunc2(myActiveSheet){
/*
var myActiveSheet = SpreadsheetApp.getActiveSheet()
*/
myActiveSheet //.autocomplete now works here
}
The new editor uses JSDoc for parameter types. So declare the parameter in the docs, and specify its type between the braces {}.
/**
* #param {SpreadsheetApp.Sheet} sheet
*/
function myfunc(sheet) {
sheet //.autocomplete now works here
}
This question already has answers here:
Call Library function from html with google.script.run
(3 answers)
Server error, google.script.run fails when using a shared library
(3 answers)
Closed last year.
I have the following code.gs
function test() {
Logger.log("Whoo hoo! test() called");
}
function showPopup() {
var html = HtmlService.createTemplateFromFile('index').evaluate().setWidth(400).setHeight(300);
SpreadsheetApp.getUi().showModalDialog(html, 'Click the button');
}
along with this index.html
<div>
<input type='button' onclick='google.script.run.test()' value='Test'>
</div>
These work fine: after running showPopup() I click on the button and the message appears in the logs example.
The problem comes when I add this project as a library to another spreadsheet, using the "Resources->Libraries..." menu item. Let's say I give the library the name "Test", then on the new spreadsheet I run Test.showPopup(), it puts up the popup. But then when I click on the button it does not call the test() function.
Instead, the console on the spreadsheet complains that "undefined is not a function". The problem appears to be that google.script.run.test() does not work when code is shared using the Libraries manager. It wants something like google.script.run.Test.test(), but I tried that and it didn't work either: "Cannot read property 'test' of undefined".
Is there some way I can use google.script.run in a shared (library) script?
or some other way I can re-use my code on other spreadsheets without having to cut-n-paste all the files to each one?
Ah, it looks like someone else reported this as a bug. Shucks. Any workarounds?
I was wondering the same thing. So far haven't seen an real answer on this.
My answer is not the best, but I managed a workaround doing this on the script:
function test() {
Test.test();
}
I'd love to know the real solution for this.
When using jQuery within the HtmlService in a Google Apps Script, are the .animate and .delay methods not supported? I can get .show() and .hide() to work, but I can't get any animations to work.
For example, in a sidebar, I would like to temporarily display a notice using:
$('#notice').show().delay(5000).hide();
The delay appears to be ignored. I've tested the following, and it works fine, so it seems that the .delay method is the only thing not working in this case. I've also tried using .animate, but it does not seem to work, either.
$('#notice').show();
Thanks.
The jQuery method .delay() won't work in-between .show() and .hide() as it can only be used in conjunction with animations. You will need to use
setTimout(function(){
$('#notice').hide();
}, 5000);
Those are not supported. Its documented in the limitations section of htmlService.
I am stuck with a pure JS script that should be included in Joomla (1.7, Mootools 1.3.2)
and raises a conflict with this library while working perfectly outside it.
Examples :
no Mootools
http://jsfiddle.net/2W87v/
with Mootools
http://jsfiddle.net/2W87v/1/
Firebug error around line 133 :
document.getElementById("pu_" + champs[i]) is null
I tried all kinds of solutions, renaming certain variables, using $ instead of document.getElementById, wrapping each function around an anonymous function. To no avail.
If someone could point in the right direction, I'd be very grateful.
mootools is prototypical.
var champs = ['surfaceMaison','surfaceGarage','terrasseCouverte','terrasseNonCouverte','cloture'];
var prix = ['pack','valeur','valeur','valeur'];
var options = ['toitureMultipentes','doucheItalienne','wcSuspendu','enduitTaloche','voletsRoulants','climGainable'];
// and..
for (var i in champs)
for (var i in options)
is a no go as is, it will go up the prototype chain and get the stuff mootools adds to the Array prototype.
in general, for var in object as a construct has always been intended for OBJECTS and not arrays. it works anyway, because in javascript you don't have a proper Array type, it's just an Object type with Array-like properties (eg, length).
loop the arrays via options.each(function(el, i) {} or a normal for loop instead.
also, you can check for hasOwnProperty:
for (var i in champs)
if (champs.hasOwnProperty(i)) {
// do the stuff
}
I have predefine MooTools.js and some another javascript called moomenu for dropdown...
However i could test the code and i come to know that "typeof(MooTool)" return undefined...
I am new to MooTool so will any body please tell me what happens there???
It's because your calling it "MooTool" instead of "MooTools"; however, if you look at the source, var MooTools only refers to an object with the version and build information. If you're trying to select an element, you want to look at the $ and $$ functions of the Element object:
http://mootools.net/docs/core/Element/Element