I want to add tooltips to Labels in UiApp. I was thinking about MousOverHandlers on each (important) Label, as there is no function like Label.setTooltip().
Is there any way to implement this functionality? The only thing I can think of doing is:
Creating a hidden Label (eh, don't really want to)
Add a MouseOverHandler to the Label I want a tooltip on
Make the hidden Label visible in the event handler
I don't really like this solution - is there a better way?
Have you tried Label.setTitle("tooltip text") directly on your widget? (works also with other widgets of course)
I guess that's what you are looking for .
Basic example testable here :
function doGet() {
var app = UiApp.createApplication();
var abs = app.createAbsolutePanel().setStyleAttributes({"background":"#FFA","padding":"60px"});
var lab = app.createLabel('Hover your mouse over this label').setTitle('There it is !');
app.add(abs.add(lab));
return app;
}
Related
I want add eventListener highlight buttonLockup with stackTemplate.
Can you guide to use this?
Thanks,
The event system in TVJS is extremely similar to that in a web browser. After all, it's just JS and a DOM. MDN's documentation on Event Handlers should be mostly relevant
To add an event listener to a specific button, just find that button (using ID or name or whatever), and use addEventListener.
var myButton = doc.getElementByName('buttonLockup')
var onSelect = function(ev) {
console.log('Button selected!')
}
myButton.addEventListener('select', onSelect)
However, depending on your use case, I've found Apple's approach in their sample apps to be quite useful. They rely on the fact that events bubble up to the root of the template, and just listen to them there. So for example:
// Given a TVML document has been presented with this somewhere in it
<buttonLockup action="doSomething">Do something</buttonLockup>
// When it's selected, doSomething
var globalOnSelect = function(ev) {
var target = ev.target;
var action = target.getAttribute('action')
if (action === 'doSomething') {
console.log('Do Something button selected');
doSomething();
}
}
doc.addEventListener('select', globalOnSelect);
I have searched arond, but cant seem to find a proper answer to this. Lets say we have a super basic program which adds two numbers from 2 input text fields togehter and prints them out. Why cant i accses variables outside the event handler function? And what do i have to do in order to achieve this? The code is on a frame.
Why does this example not work? :
btn.addEventListener(MouseEvent.CLICK, cal);
var fnum:Number = Number(txt1.text);
var snum:Number = Number(txt2.text);
function cal(evt:MouseEvent){
txtOutput.text = String(fnum + snum);
}
And this example work?:
btn.addEventListener(MouseEvent.CLICK, cal);
function cal(evt:MouseEvent){
var fnum:Number = Number(txt1.text);
var snum:Number = Number(txt2.text);
txtOutput.text = String(fnum + snum);
}
I hate to be this guy, but I can't get it to replicate whats happening for you..
The only assumption that I can make is that the txt1.text & txt2.text aren't set yet when the button is clicked in example 1. Feel free to zip your project and dropbox it to me if you want me to investigate further :)
The following code should write the inverse of true/false as found in the textbox back into the textbox when the button is clicked - but it doesn't work correctly. It will work correctly one way, but not the other (the one that works is whichever ClickHandler was defined last). I've tried using validateNotMatches too but no joy.
If I change the code so that the label's text is updated instead of the textbox's then that works fine.
I am aware of suggested workarounds such as using two buttons, but I just want to know if I'm doing something wrong or if this looks like a bug in GAS. Thanks.
function doGet(e)
{
var app = UiApp.createApplication();
var tb = app.createTextBox().setText('true');
var button = app.createButton('button');
var label = app.createLabel().setText('-');
button.addClickHandler(app.createClientHandler()
.validateMatches(tb, 'true')
//.forTargets(label).setText('false')
.forTargets(tb).setText('false')
);
button.addClickHandler(app.createClientHandler()
.validateMatches(tb, 'false')
//.forTargets(label).setText('true')
.forTargets(tb).setText('true')
);
return app.add(app.createHorizontalPanel().add(tb).add(button).add(label));
}
It's not a bug... both events fire. The validation happens on the current state of the widget, not on the state when the event was fired, so after you flip it to "false" the second handler validates and flips it back to "true".
I developed an app that runs from a Spreadsheet. It has a formatted screen, ie. doc.show(app
). There is a mass change function. I'd like to prompt the user for 'Are you sure ... OK to Continue'.
The ideal solution would be a pop-up form with an "OK to continue" response.
I can't find a way to prompt the user and accept a response that doesn't simultaneously take down the formatted screen.
I know there must be a easy way to do this. I searched this forum and others, but cannot find a solution that applies to Google Spreadsheets.
When using the GUI Builder I've found a very simple solution that is to create a panel or a label that is actually masking the whole UI (or part of it) and that is normally invisible.
When I make it visible I can click on it, it turns invisible again and I'm back on the standard UI. It uses the ability in GUI builder to move elements backwards and forwards so masking is very easy (a sort of multi layer design). I guess the same behavior is achievable with script defined UI but I'm not sure how...
regards,
Serge
EDIT : For information : I just set up an interface using this technique and I noticed that panels that have been made invisible must be restored along with all their elements otherwise they reappear empty. Using Clienthandlers here is an example with two panels and two buttons that do the job :
var panhandler0 = app.createClientHandler()
.forTargets(panel1).setVisible(false);// hide panel1 when button 'ENTER'on panel1 is pressed
enter.addClickHandler(panhandler0);
var panhandler1 = app.createClientHandler()
.forTargets(panel2,msg,grid2).setVisible(true);// show panel2 when button 'ENTER' on panel1 is pressed
enter.addClickHandler(panhandler1);
var panhandler2 = app.createClientHandler()
.forTargets(panel2,msg,grid2).setVisible(true);// re-show panel2 when button 'retry'on panel2 is pressed
retry.addClickHandler(panhandler2);
var panhandler3 = app.createClientHandler()
.forTargets(panel2).setVisible(false);// hide panel2 when button 'retry'on panel2 is pressed
retry.addClickHandler(panhandler3);
var panhandler4 = app.createClientHandler()
.forTargets(panel1,txt,grid,hpanel).setVisible(true);// re-show panel1 when button 'retry'on panel2 is pressed
Works nicely !
You can use Browser.MsgBox() and add buttons into it for users confirmation.
Refrence URL
https://developers.google.com/apps-script/class_browser
This is indeed not an easy thing to do. You'll have to use your own GUI (formatted screen) to show the message. This way you can restore the state of your GUI again. Here is an example:
function uiTest() {
var app = UiApp.createApplication().setTitle("UI");
app.add(app.createGrid(1,1).setId('main'));
createGUI(app,{});
SpreadsheetApp.getActive().show(app);
}
function createGUI(app,p) {
var panel = app.createVerticalPanel();
var handler = app.createServerHandler('handler').addCallbackElement(panel);
panel.add(
app.createTextBox().setName('text').setId('text').setText(p.text ? p.text : "")).add(
app.createButton('Do it').addClickHandler(handler));
app.getElementById('main').setWidget(0,0, panel);
}
function handler(e) {
var app = UiApp.getActiveApplication();
var hidden = app.createHidden('oldValues', JSON.stringify(e.parameter));
app.getElementById('main').setWidget(0,0, app.createVerticalPanel().add(
hidden).add(
app.createLabel("Question message")).add(
app.createButton('Ok').addClickHandler(app.createServerHandler('after').addCallbackElement(hidden))));
return app;
}
function after(e) {
var app = UiApp.getActiveApplication();
createGUI(app,JSON.parse(e.parameter.oldValues));
return app;
}
The difficulty will really depend on how much state you need to restore. If none, then it's a lot, lot easier. In this example I restore the value of the textbox. You can type in anything there to see that it will be there after the popup.
I am trying to put a button inside of an Openlayers popup. While the button appears to display correctly with the following code, the function 'handlerFunc' does not execute when the button is clicked. The segment of code I have posted is all within another function (so handlerFunc is actually a nested function). I'm using JQuery for the button itself. Any ideas on what might be going wrong? Thanks!
var feature = new OpenLayers.Feature(presences, ll);
feature.popupClass = popupClass;
feature.data.popupContentHTML = "<button id='popupButton'>Click me</button>";
feature.data.overflow = (overflow) ? "auto" : "hidden";
feature.data.icon = markerIcon;
$('#popupButton').button();
$('#popupButton').click(handlerFunc);
function handlerFunc() {
// do something
}
Most likely reason is that your button doesn't exist when you bind to a click event. $('#popupButton') returns null. Instead of using $('#popupButton').click(handlerFunc); try $('#popupButton').live('click', handlerFunc);. That means that we bind to an event not only when DOM is built, but when object appears.