Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a drop down list in Input Box?

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?

like image 367
HackCode Avatar asked Oct 02 '15 08:10

HackCode


People also ask

How do I create a fillable drop-down list in Excel?

From the DATA tab, select Data Validation. Click Data Validation in the drop-down list. In the dialog box, select List from the Allow drop-down menu. In the source field, type the choices you'd like your drop down menu to include, separated by commas.

How do I activate a TextBox if I select an option in drop down box?

When an item (option) is selected in DropDownList (HTML SELECT), the EnableDisableTextBox JavaScript function is executed. Inside this function, based on whether the Other option (item) is selected, the TextBox will be enabled else disabled. The HTML Markup consists of a DropDownList (HTML SELECT) and a TextBox.


1 Answers

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>
like image 161
Alan Wells Avatar answered Oct 23 '22 03:10

Alan Wells