different item style for items in listbox - google-apps-script

As listbox only accept string as items, is there a way to add items with different style? Is there any class to do this?
Ex:
Item1 in red
Item2 in green
Thanks.

var tree = app.createTree();
tree.addItem(app.createTreeItem(
app.createLabel("Tree Item 1").setStyleAttribute("color","green")));
tree.addItem(app.createTreeItem(
app.createLabel("Tree Item 2").setStyleAttribute("color","red")));
Edit: Sorry you said List but I read Tree for some reason.
No, this cannot be done, because the underlying browser list widgets don't support it. It's possible to achieve something roughly similar using HtmlService and jQuery, but not in UiApp.

Related

Google Forms discrepancy

When I add a list item to a Google Form I can set and get choices.
If I select a list item from an existing form I cannot.
items = form.getItems();
for (i=0;i<items.length;i++){
Logger.log(items[i].getType());
if (items[i].getTitle() == 'A List'){
choices = items.getChoices();
}
}
I can see the items are of type "List" in the log but getChoices throws an error
TypeError: Cannot find function getChoices in object item....
Is this a bug in Apps Script? Is there something I can do to cast the item and make sure it is of the right type?
Thanks
Jeremy
Please reffer to the documentation here. As you can see an item does not have a .getChoices() method. This method is available in specific types of items, like ListItem. So you need to specifically do something like
choices = items[i].asListItem().getChoices()
Remember that items is an array and you need to specify which item you are getting choices for. You then need to specify what type of item it is (i.e. a list item) and only then you can get the choices. If this is something you need to do for any type of item, then you will need to figure out how to check what kind of item it is and then get it as that item type.

How to use item renderer to view multiple fields?

Our app contacts the server, and get a json based array, each item has:
First_Name
Last_Name
Image_Url
So, how to use the item renderer so that we can use custom data template to view name and image?
Also, can we have access to the json item being rendered from inside the renderer code?
Any examples would be highly appreciated.
http://help.adobe.com/en_US/flex/using/WS77c1dbb1bd80d3836ecbb5ec129ec77b1e1-8000.html
just above the 'Controlling the background display of an item renderer' section, there is a custom itemrenderer example, you can use it.
Find below link to add custom item renderer
http://www.adobe.com/devnet/flex/videotraining/exercises/ex4_03.html

Flex MenuBar : Stay open on itemclick

I have a MenuBar with objects that have children of type="check". E.g.:
Menu
Menu Item A
/ List item Check 1A
/ List item Check 2A
/ List item Check 3A
Menu Item B
/ List item Check 1B
/ List item Check 2B
My question is as follows: How can i avoid the MenuBar from hiding when the user clicks an item (itemClick event)? I want the user to be able to "check" several items at once, without the menu hiding/closing.
Bonus question: What is the easiest way to reset all the checked items? :-)
Best Regards,
Sebastian
The only way I can advise you is to do monkey patching of the class Menu. I have tried to do it by me, it works as you described in your task.
The main reason to do it is, that the functions we need to redefine use private members of this class. So we can't just override them.
The aim of our mission is to patch the function
function mouseUpHandler(event:MouseEvent):void{...}
At its end you can see the call
hideAllMenus();
We should add a new variable to control whether or not our item is of type "check". So you need to add this line in the beginnig
var isCheck:Boolean = _dataDescriptor.getType(item) == "check";
and this condition at the end
if (!isCheck) hideAllMenus();
Don't forget to do a trick to let your patched class be loaded before the SDK's one.
You can read about it here.
Here is my working example. Menu1 has only check items and Menu2 only normal ones.
The whole project can be found here

Accessing ListBox selected item via UiApp.getActiveApplication().getElementByID()

Currently I am using UiService to create a form and I uses ListBox, from what I understand to pass a value via handler will be something like e.parameter.[Name of ListBox] to access the selected item.
Does anyone know is it possible to use like app.getElementById([Name of ListBox]) to access the selected item. The reason I am using this method is because my list of ListBox-es are dynamic.
I spent some time looking for this answer as well, but finally I tried one idea and it worked.
You can use e.parameter as an array so you can these two will give the same:
e.parameter.LIST_BOX_NAME
and
e.parameter['LIST_BOX_NAME']
So in the second sample any dynamic list box ID can be used. I use same handler for all added dropdown list and have this code to check what dropdown was changed and what value it has now:
if (e.parameter[e.parameter.source] == 'a'){
To change the content of the listBox you can use app.getElementById('ID of the listBox'), from there you can clear() and addItems again but you cannot read the listItems.
When I need to do this I usually store the list of items somewhere else, in a place that I can read anytime, for example the list of items can be stored as a string in the listBox tag itself so I have all items at hand to repopulate the listBox after I have clear it.

It is possible to add to Unordered List during runtime

I have a simple HTML page with an Unordered list. Is it possible to have an input field where you could add more to the list and it would be saved after you submitted it. What I would like to add would be the content inside of an <li> tag as well as the <li> tags themselves.
Thanks,
Here is a jsfiddle with a demo of what I think you want to achieve: http://jsfiddle.net/mvJNq/25/
Note that I can not answer as to how you should do this on the server, as that depends on how your serverside code, database etc is set up. However, if all you want is to display it as HTML and not have it saved as the user navigates away, you won't need the Submit button at all - then you just need the "Add" functionality.
Yes, it is possible - no, it will not be pretty. Here is what you would do:
create your base form with any default list items/inputs
use jQuery/JavaScript to bind an event handler to a button that you click when you want to add another item (alternatively, you could skip this step and just have another item appear by default)
on your event (be it checking that all input boxes have user-entered text, or the click event in step two) add another list item using jQuery.append(...)
ensure that you have a hidden input field to be used as a "counter" to keep track of the total number of list items and increment the value of this counter each time you add a new list item (note: you may need to use the ParseInt() method, depending on how you design the code for this field)
the page that is receiving the form's inputs should first read the hidden field so that it knows how many items to add, and then you should loop through the items (for or while loop) to add them correctly
Note: I don't know what Server-Side language you are using to handle receiving the form so step 5 is a fairly generic and universally viable option
Sure, it's possible.
The complexity of this comes in when you want to "save" the items. If the user leaves the page and comes back later will that data be available? If so, you will need a database like mySQL or similar. The li tags can be stored as well, but why?
If you just need that information available in that session you can store in a JavaScript variable and have it loop through the variable and spit them out as <li>'s
If you did want to use an add button instead of submit:
$('#addButton').click(function(){
var savedContent = $('#input').val();
}
To create + insert the <li>you can use javascript to create the element and append it to the ul. If you have more than one ul change the index:
var content = document.createElement('li');
content.innerText = savedContent;
document.getElementsByTagName('ul')[0].appendChild(content);