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)

1  
static S hselect_list(Collection<S> entries, O... params) {
2  
  new StringBuilder buf;
3  
  S selected = null;
4  
  if (odd(l(params))) {
5  
    selected = str(first(params));
6  
    params = dropFirst(params);
7  
  }
8  
  int i = indexOf(params, "allowEmpty");
9  
  if (even(i)) {
10  
    buf.append("<option></option>\n");
11  
    params[i] = params[i+1] = null;
12  
  }
13  
  if (nempty(entries)) for (S k : entries) {
14  
    S value = k;
15  
    buf.append(tag("option", htmlencode(str(or(value, ""))),
16  
      value := k,
17  
      selected := eq(selected, k) ? "selected" : null)).append("\n");
18  
  }
19  
  ret tag("select", buf, params) + "\n";
20  
}

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: 184 / 188
Version history: 2 change(s)
Referenced in: [show references]

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