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

47
LINES

< > BotCompany Repo | #1032529 // HTMLForm

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

Libraryless. Click here for Pure Java version (5107L/30K).

1  
persistable sclass HTMLForm {
2  
  new L<Row> rows;
3  
  S tableClass = "responstableForForms";
4  
  new SS hiddenValues;
5  
  
6  
  bool renderForm = true; // render <form> tag
7  
  S formAction; // action URL of <form>
8  
  
9  
  persistable asclass Row {
10  
    S label; // HTML
11  
    
12  
    abstract O contents(); // HTML
13  
  }
14  
  
15  
  persistable sclass LiteralRow extends Row {
16  
    S contents;
17  
    
18  
    *(S *label, S *contents) {}
19  
    
20  
    O contents() { ret contents; }
21  
  }
22  
  
23  
  S css() {
24  
    ret eq(tableClass, "responstableForForms") ? hcss_responstableForForms() : "";
25  
  }
26  
  
27  
  S get() { ret hcss(css()) + html(); }
28  
  
29  
  S html() {
30  
    LLS matrix = map(rows, row -> ll(row.label, strOrEmpty(row.contents())));
31  
    S table = htableRaw_valignTop(matrix, empty(tableClass) ? litparams(border := 1, cellpadding := 4) : litparams(class := tableClass));
32  
    table += hhiddenMulti(hiddenValues);
33  
    ret renderForm ? hpostform(table, action := formAction) : table;
34  
  }
35  
  
36  
  void add(S label, O contents) {
37  
    rows.add(new LiteralRow(label, strOrEmpty(contents)));
38  
  }
39  
  
40  
  void addButton(S text) {
41  
    add("", hsubmit(text));
42  
  }
43  
  
44  
  void addHidden(S name, S value) {
45  
    hiddenValues.put(name, value);
46  
  }
47  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032529
Snippet name: HTMLForm
Eternal ID of this version: #1032529/12
Text MD5: a38bae431f49838235b8fa2ae35589b2
Transpilation MD5: d8e1b5defa0003787d3054a6c4cfe1e4
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-13 17:54:00
Source code size: 1223 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 154 / 321
Version history: 11 change(s)
Referenced in: [show references]