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

31
LINES

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

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (3197L) is out of date.

1  
sS hselect_list(S name, Cl<S> entries, O... params) {
2  
  ret hselect_list(entries, paramsPlus_skipFirst(params, +name));
3  
}
4  
5  
sS hselect_list(Cl<S> entries, 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  
  ifdef hselect_list_debug
13  
    printVars_str(+selected);
14  
  endifdef
15  
  int i = indexOf(params, "allowEmpty");
16  
  if (even(i)) {
17  
    buf.append("<option></option>\n");
18  
    params[i] = params[i+1] = null;
19  
  }
20  
  if (nempty(entries)) for (S k : entries) {
21  
    S value = k;
22  
    bool isSelected = eq(selected, k);
23  
    ifdef hselect_list_debug
24  
      if (isSelected) print("Selected: " + k);
25  
    endifdef
26  
    buf.append(hfulltag option(htmlencode(str(or(value, ""))),
27  
      value := k,
28  
      selected := isSelected ? html_valueLessParam() : null)).append("\n");
29  
  }
30  
  ret hfulltag("select", buf, params) + "\n";
31  
}

Author comment

Began life as a copy of #1007620

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1013066
Snippet name: hselect_list - HTML <select> tag from list of strings - hselect_list([name,] entries, [selected key,] params)
Eternal ID of this version: #1013066/12
Text MD5: 393a1407e196d8fa8579c24779dae345
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-23 19:20:32
Source code size: 943 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 468 / 585
Version history: 11 change(s)
Referenced in: [show references]