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

25
LINES

< > BotCompany Repo | #1007620 // hselect - HTML <select> tag from map - hselect([name,] map, [selected key,] params)

JavaX fragment (include)

1  
sS hselect(S name, Map map, O... params) {
2  
  ret hselect(map, paramsPlus_skipFirst(params, +name));
3  
}
4  
5  
sS hselect(Map map, O... params) {
6  
  new StringBuilder buf;
7  
  S selected = null;
8  
  if (odd(l(params))) {
9  
    selected = str(first(params));
10  
    params = dropFirst(params);
11  
  }
12  
  int i = indexOf(params, "allowEmpty");
13  
  if (even(i)) {
14  
    buf.append("<option></option>\n");
15  
    params[i] = params[i+1] = null;
16  
  }
17  
  if (nempty(map)) for (O key : keys(map)) {
18  
    O value = map.get(key);
19  
    S k = str(key);
20  
    buf.append(tag("option", htmlencode(str(or(value, ""))),
21  
      value := k,
22  
      selected := eq(selected, k) ? "selected" : null)).append("\n");
23  
  }
24  
  ret tag("select", buf, params) + "\n";
25  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1007620
Snippet name: hselect - HTML <select> tag from map - hselect([name,] map, [selected key,] params)
Eternal ID of this version: #1007620/10
Text MD5: 8f1965ece4a948e8842e4e6169843ff0
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-10 14:00:20
Source code size: 728 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 467 / 510
Version history: 9 change(s)
Referenced in: [show references]