aardbol
aardbol

Reputation: 2295

Qooxdoo form elements and getSelection()

Here's my code:

var sb = new qx.ui.form.SelectBox();

sb.add( new qx.ui.form.ListItem("English") );
sb.add( new qx.ui.form.ListItem("Nederlands") );
sb.add( new qx.ui.form.ListItem("Deutsch") );
sb.add( new qx.ui.form.ListItem("français") );
sb.add( new qx.ui.form.ListItem("Српски") );

How do I use setSelection() to select "Deutsch", and what if the items are numeric values? Can I also set values for these labels or is SelectBox() limited to labels?

For example:

value: en, label: English
value: de, label: Deutsch
etc.

Upvotes: 3

Views: 1453

Answers (2)

Roman Nik
Roman Nik

Reputation: 43

Maybe this example will be useful for you too:

var sb = new qx.ui.form.SelectBox();
var a = ["English", "Nederlands", "Deutsch", "Français", "Српски"];
var model = new qx.data.Array(a);
var controller = new qx.data.controller.List(model, sb);
controller.setSelection(model.slice(0,3));

At last line model.slice(0,3) returns subarray of model with three elements: from "English" to "Deutsch". And last element in this subarray will be "selected" by default.

See "Data Binding" in qooxdoo's manual for details.

Upvotes: 0

dashhunter
dashhunter

Reputation: 111

Take a look at the example code below.

You can specify a model with each ListItem for storing additional information. It can act as value property on form items for example. See http://demo.qooxdoo.org/1.0.x/apiviewer/#qx.ui.form.ListItem

  var selectBox = new qx.ui.form.SelectBox();

  selectBox.add( new qx.ui.form.ListItem("English", null, "en" ));
  selectBox.add( new qx.ui.form.ListItem("Nederlands", null, "nl" ));
  var defaultItem = new qx.ui.form.ListItem("Deutsch", null, "de" );
  selectBox.add(defaultItem );
  selectBox.add( new qx.ui.form.ListItem("français", null, "fr"));
  selectBox.add( new qx.ui.form.ListItem("Српски", null, "ru"));

  selectBox.setSelection([defaultItem]);
  selectBox.addListener("changeSelection", function(e) {

    //Read model data from listitem
    this.debug("changeSelection: " + e.getData()[0].getModel());
  });

Upvotes: 6

Related Questions