Quantcast
Channel: PTC Community: Message List - Arbortext
Viewing all articles
Browse latest Browse all 3717

Re: Multiple-selection list box

$
0
0

Hi Jing--

 

You can do this in all ACL if you prefer. There is a set of dialog functions, most of which start with dlgitem_* for interacting with dialogs using ACL. This includes adding new controls or listitems, and reading results.

 

Here is a simple example that uses all ACL to dynamically build a dialog listing all the titles in the current document, and letting the user select one or more of them. Note the use of dlgitem_add_callback() to attach behavior to the OK button, which avoids the need to insert javascript code in the XUI document itself. (If you prefer Javascript, it will also work perfectly well to put it in the XUI markup, just as you might with a static dialog.)

 

--Clay

 

function showdlg() {

  # create new dialog document

  local dlgoid = _xmldlg::newDialog("titledlg","Choose titles");

  # add listbox and OK button

  insert("<listbox id='titlelist' type='multiple'><listitem id='id_foo'>foo</listitem></listbox><button id='okbtn' type='OK' label='OK'/>", oid_doc(dlgoid));

  local dlgwin = _xmldlg::newWindow(dlgoid);

  # get all titles from current document and store content in titletext[] array

  local titles[],t;

  xpath_nodeset(titles,"//title");

  local titletext[];

  for (t = 1; t <= count(titles); t++) {

    titletext[t] = oid_content(titles[t]);

  }

  # set the listbox to include the titles

  dlgitem_set_list_array(dlgwin, 'titlelist', titletext);

  # attach the callback to the OK button

  dlgitem_add_callback(dlgwin, 'okbtn', 'okbtncallback');

  # everything is ready, show the dialog

  window_show(dlgwin,1);

}

 

function okbtncallback(windowid, dlgitem, eventtype, eventsubtype, detail) {

  if (eventtype == "ITEM_CHANGED") {

    local selected[];

    local labels[];

    # get all titles in list

    dlgitem_get_list_array(windowid, "titlelist", labels);

    # get selected title indexes

    dlgitem_get_select_array(windowid, "titlelist", selected);

    local msg = "You picked:\n\n";

    # for each selected title, use the index to look up the listitem text

    for (s in selected) {

      msg .= "  " . labels[selected[s]] . "\n";

    }

    # do something useful with selected items here

    response(msg);

  }

}

 

showdlg();


Viewing all articles
Browse latest Browse all 3717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>