Note that there are some explanatory texts on larger screens.

plurals
  1. POhandler design for dynamically created listboxes
    primarykey
    data
    text
    <p>I'm trying to make a UI that allow users to select an action for each agenda item in a spreadsheet. After a user select an action, I would like to update the spreadsheet with the selection. Since the data in the spreadsheet are not static, the UI was written dynamically. </p> <p>This is how I created the listboxes :</p> <pre><code>// add labels and a drop down box of actions for each agenda item mark for today for (i = 0; i &lt; labels.length; i++) { // labels is an array of objects var topic = labels[i]['topic']; // add label to grid myGrid.setWidget(i, 0, myApp.createLabel(topic)); // the id of each listbox is the content of its corresponding label var id = ObjApp.camelString(topic) var lboxActions = myApp.createListBox().setId(id); //add items to listbox lboxActions.addItem('Select'); lboxActions.addItem('Add to agenda'); lboxActions.addItem('Move to another meeting'); lboxActions.addItem('Move to a special meetin'); lboxActions.addItem('Move to email'); //add drop down list to grid myGrid.setWidget(i, 1, lboxActions); } </code></pre> <p>I have 3 questions:</p> <h2>1) Which is a better design?</h2> <p>a) <strong>Design 1</strong>: a save button next to each listbox. </p> <p>b) <strong>Design 2</strong>: one submit button at the bottom to save every entry</p> <h2>2) How would I collect information on what the user select? How would I write such handlers? I added the following code for each design but I don't think I'm doing it right.</h2> <p>a) <strong>Design 1</strong>: the following lines of code were added to the for loop described above</p> <pre><code>var buttonSave = myApp.createButton('Save'); myGrid.setWidget(i, 2, buttonSave); var handlerSelection = myApp.createServerHandler('selectAction'); handlerSelection.addCallbackElement(mainPanel); buttonSave.addClickHandler(handlerSelection); </code></pre> <p>b) <strong>Design 2</strong>: the following lines of code were added outside the for loop</p> <pre><code>//update spreadsheet when user click "submit" var handlerUpdate = myApp.createServerHandler('responseToSubmit'); handlerUpdate.addCallbackElement(mainPanel); buttonSubmit.addClickHandler(handlerUpdate); mainPanel.add(myGrid); mainPanel.add(buttonSubmit); myApp.add(mainPanel); </code></pre> <h2>3) How do I write functions for the handlers? These are not correct because I wasn't able to extract the information from the list boxes.</h2> <p>a) <strong>Design 1</strong></p> <pre><code>function responseToSave(e) { var name = e.parameter.source; var selection = e.parameter.name; var selectionObj = new Object(); selectionObj['status'] = selection; selectionObj['name'] = name; choicesMade.push(selectionObj) Logger.log(choicesMade); return choicesMade; } </code></pre> <p>b) <strong>Design 2</strong></p> <pre><code>function responseToSubmit(e) { var myApp = UiApp.getActiveApplication(); for (i=0; i &lt; labels.length; i++) { var lboxId = ObjApp.camelString(labels[i]['topic']); //[EDIT] e.parameter.lboxId would not work because lboxId is a string var selection = e.parameter[lboxId]; choicesMade[labels[i]] = selection; } Logger.log(choicesMade); return choicesMade; } </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload