Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1013066 - hselect_list - HTML <select> tag from list of strings - hselect_list(entries, [selected key,] params)

JavaX fragment (include)

static S hselect_list(Collection<S> entries, O... params) {
  new StringBuilder buf;
  S selected = null;
  if (odd(l(params))) {
    selected = str(first(params));
    params = dropFirst(params);
  }
  int i = indexOf(params, "allowEmpty");
  if (even(i)) {
    buf.append("<option></option>\n");
    params[i] = params[i+1] = null;
  }
  if (nempty(entries)) for (S k : entries) {
    S value = k;
    buf.append(tag("option", htmlencode(str(or(value, ""))),
      value := k,
      selected := eq(selected, k) ? "selected" : null)).append("\n");
  }
  ret tag("select", buf, params) + "\n";
}

Author comment

Began life as a copy of #1007620

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1013066
Snippet name: hselect_list - HTML <select> tag from list of strings - hselect_list(entries, [selected key,] params)
Eternal ID of this version: #1013066/3
Text MD5: 7d5a1f8142362a3ee5f3f8d2eeab3b77
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-08 06:13:00
Source code size: 614 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 185 / 189
Version history: 2 change(s)
Referenced in: #1006654

Formerly at http://tinybrain.de/1013066 & http://1013066.tinybrain.de