1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.web.elements.textarea;
7 
8 import diamond.web.elements.input;
9 
10 /// Wrapper around a textarea input.
11 final class TextArea : Input
12 {
13   private:
14   /// The associated form.
15   string _form;
16   /// The rows.
17   size_t _rows;
18   /// The columns.
19   size_t _columns;
20 
21   public:
22   final:
23   /// Creates a new textarea input.
24   this()
25   {
26     super("textarea");
27   }
28 
29   @property
30   {
31     /// Gets the form.
32     string form() { return _form; }
33 
34     /// Sets the form.
35     void form(string newForm)
36     {
37       _form = newForm;
38 
39       addAttribute("form", _form);
40     }
41 
42     /// Gets the rows.
43     size_t rows() { return _rows; }
44 
45     /// Sets the rows.
46     void rows(size_t newRows)
47     {
48       _rows = newRows;
49       addAttribute("rows", _rows);
50     }
51 
52     /// Gets the columns.
53     size_t columns() { return _columns; }
54 
55     /// Sets the columns.
56     void columns(size_t newColumns)
57     {
58       _columns = newColumns;
59       addAttribute("cols", _columns);
60     }
61   }
62 
63   protected:
64   /// Generates the appropriate html for the element.
65   override string generateHtml()
66   {
67     import std..string : format;
68 
69     return "%3$s<%1$s %2$s>%4$s</%1$s>".format
70     (
71       super.tagName, super.attributeHtml(),
72       super.label && super.label.length && super.id && super.id.length ?
73       "<label for=\"%s\">%s</label>".format(super.id, super.label) : "",
74       super.value ? super.value : ""
75     );
76   }
77 }