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

27
LINES

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

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

Libraryless. Click here for Pure Java version (2775L/17K).

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);
  }
  ifdef hselect_list_debug
    printVars_str(+selected);
  endifdef
  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;
    bool isSelected = eq(selected, k);
    ifdef hselect_list_debug
      if (isSelected) print("Selected: " + k);
    endifdef
    buf.append(hfulltag option(htmlencode(str(or(value, ""))),
      value := k,
      selected := isSelected ? html_valueLessParam() : 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 11 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pzhvpgtvlbxg, 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/7
Text MD5: 437d7e20b64970bc2006fd56cba2b048
Transpilation MD5: dd3a9e764b518a6a1d737cd25ec86df7
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-05 16:12:20
Source code size: 825 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 203 / 220
Version history: 6 change(s)
Referenced in: [show references]

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