Infeasible
Status Update
Comments
tf...@tftshare.ca <tf...@tftshare.ca> #2
Why don't you try storing the list box values in a cache (fast) and create an array using CSV from the listbox contents? Then you can cycle through, find your match and remove accordingly using a search. Still not very elegant, but it works.
an...@gmail.com <an...@gmail.com> #3
This is absurd that once you put the items into the listbox you have no way of iterating through the items at a later point. A getItemCount and getItemText and getItemValue seem so obviously required.
Just a simple example. I populate the listbox with items from a database. I then have to programatically update the selected item in the listbox. But I would have to go back to the original database source, just to get the index of the item I was wanted to have selected, instead of looking at the cached data I have right there in the listbox !!!
The functionality is right there in the GWT, why can it not be exposed in the Apps Script environment ? Crazy.
Just a simple example. I populate the listbox with items from a database. I then have to programatically update the selected item in the listbox. But I would have to go back to the original database source, just to get the index of the item I was wanted to have selected, instead of looking at the cached data I have right there in the listbox !!!
The functionality is right there in the GWT, why can it not be exposed in the Apps Script environment ? Crazy.
an...@gmail.com <an...@gmail.com> #4
Regarding the comment of using a cache. That seems quite silly. As the cache is the database in terms of the original source, and then the cache is the actual list box. To have to maintain a third set of the listbox items just to use the listbox is silly.
So far the only option I have is to go back to the original database source each time and completely refresh the items in the listbox.
So far the only option I have is to go back to the original database source each time and completely refresh the items in the listbox.
ko...@gmail.com <ko...@gmail.com> #5
Unfortunately it's not possible to get the current state of a widget in UiApp. You can get the value of the listbox using as a parameter to a callback function, but it's not possible to get a listing of the items in the list. Your best option is likely what was already mentioned, use the CacheService to store a copy of the list items and clear and repopulate the listbox.
[Deleted User] <[Deleted User]> #6
Agreed!! I really need a getValue, getText and getItemCount Implementation on listbox.
[Deleted User] <[Deleted User]> #7
Why is this true? Is there a motivation not to add this? It seems like very basic functionality.
cm...@unitec.edu <cm...@unitec.edu> #8
//Add a handler to the ListBox when its value is changed
var handler = app.createServerChangeHandler('showSelectedinfo');
handler.addCallbackElement(listBox);
listBox.addChangeHandler(handler);
var infoLabel = app.createLabel('listBoxItemsValueHere').setId('info');
//This functions displays the infolabel with when ListBox value is changed
function showSelectedinfo(e){
var app = UiApp.getActiveApplication();
app.getElementById('info').setText('You selected :'+e.parameter.myList).setVisible(true)
.setStyleAttribute('color','#008000');
return app;
}
hi guys now help me to get index value please!
var handler = app.createServerChangeHandler('showSelectedinfo');
handler.addCallbackElement(listBox);
listBox.addChangeHandler(handler);
var infoLabel = app.createLabel('listBoxItemsValueHere').setId('info');
//This functions displays the infolabel with when ListBox value is changed
function showSelectedinfo(e){
var app = UiApp.getActiveApplication();
app.getElementById('info').setText('You selected :'+e.parameter.myList).setVisible(true)
.setStyleAttribute('color','#008000');
return app;
}
hi guys now help me to get index value please!
[Deleted User] <[Deleted User]> #9
can anyone tell how I iterate through the values of the listbox.
Description
According to the ListBox documentation there is no way to iterate through the list items and retrieve either name or value of an item.
However in the GWT documentation, these members exist and are obviously needed for:
- removing an item with a given value/name in the list box
- reordering list box items based on the item values or names
Look at the following case:
ListBox with items (name,uniqueId) in a UI, two buttons (create new, delete).
For the 'delete' functionality I want to be able to write this:
// This is the clickhandler function for the button 'delete'
function deleteItem(e) {
var itemId = e.parameter.listBox;
// some code to delete the item with unique Id 'itemId' in a database
// now we need to remove the ListBox item in the UI
var app = UiApp.getActiveApplication();
var listBox = app.getElementById('listBox');
for (i=1; i<listBox.getItemCount()+1; i++) {
if (listBox.getValue(i) == itemId) {
listBox.removeItem(i);
}
}
}
The GAS ListBox UI element is IMHO currently crippled. Please make it useful and implement the members that already exist in the underlying GWT ListBox!
All the best
Mario
PS:
Workarounds (however ugly):
A current workaround, however ugly, is using .clear() and re-initialize the ListBox with the stored or generated items.
There are other workarounds by using a global variable but this doesn't work if all the ListBox modifying code is in the same function (not clickhandlers).
If there are other ways to emulate the desired behaviour please let me know.