How to create a drop down list in Input Box?
Asked Answered
A

2

7

I created Browser.inputBox which accepts only a single text. However I need to make a drop down list where I can choose from the list instead of typing the string myself.

A screenshot of the inputBox I created on clicking Odoo (in menu bar)>Settings:

A screenshot of the inputBox

Here is the function that is being triggered:

function menu_settings(params) {
  if (!params){
    params = [["url", "URL"], ["dbname", "Database Name"], ["username", "username"], ["password", "password"]];
  }
  for (var i = 0; i < params.length; i++){
    var input = Browser.inputBox("Server Settings", params[i][1], Browser.Buttons.OK_CANCEL);
    if (input === "cancel"){
      break;
    }
    else{
      ScriptProperties.setProperty(params[i][0], input);
    }
  }
}

Basically instead of typing the text, I need a drop list with predefined values.

I was checking the Browser class and I saw there is no such drop down list option. Most solutions that I have seen use DataValidation from texts input in the cells. But I want to give the list for the dropdown in my code and nothing on the spreadsheet.

How do I implement this?

Adamina answered 2/10, 2015 at 8:1 Comment(1)
Instead of Browser.inputBox use htmlService do display a modelessDialog with a select on it.Smalltime
B
8

This is the code to open an HTML dialog:

function fncOpenMyDialog() {
  //Open a dialog
  var htmlDlg = HtmlService.createHtmlOutputFromFile('HTML_myHtml')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setWidth(200)
      .setHeight(150);
  SpreadsheetApp.getUi()
      .showModalDialog(htmlDlg, 'A Title Goes Here');
};

You need an HTML file.

HTML_myHtml.html

<select name="nameYouWant">
  <option value="something">Text</option>
  <option value="anything">Drop Down Selection</option>
</select>

<hr/>
<ul>
  <li>This is a list.</li>
  <li>This is line two.</li>

</ul>

<button onmouseup="closeDia()">Close</button>

<script>
  window.closeDia = function() {
    google.script.host.close();
  };
</script>
Benuecongo answered 3/10, 2015 at 12:32 Comment(0)
S
0

I would like to add to Alan Wells Answer with a link for adding and HTML

Create and Serve HTML

Soubise answered 6/5 at 19:37 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewWithoutdoors

© 2022 - 2024 — McMap. All rights reserved.