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.form; 7 8 import diamond.core.apptype; 9 import diamond.http.method; 10 import diamond.web.elements.block; 11 import diamond.web.elements.input; 12 13 /// Wrapper around a form. 14 final class Form : Block!Input 15 { 16 private: 17 /// The action. 18 string _action; 19 /// The mime-type. 20 string _mimeType; 21 22 static if (isWeb) 23 { 24 /// The http method. 25 HttpMethod _method; 26 } 27 else 28 { 29 /// The http method. 30 string _method; 31 } 32 33 public: 34 final: 35 /// Creates a new form. 36 this() 37 { 38 super("form"); 39 } 40 41 @property 42 { 43 /// Gets the action. 44 string action() { return _action; } 45 46 /// Sets the action. 47 void action(string newAction) 48 { 49 _action = newAction; 50 51 addAttribute("action", _action); 52 } 53 54 /// Gets the mime-type. 55 string mimeType() { return _mimeType; } 56 57 /// Sets the mime-type. 58 void mimeType(string newMimeType) 59 { 60 _mimeType = newMimeType; 61 62 addAttribute("enctype", _mimeType); 63 } 64 65 static if (isWeb) 66 { 67 /// Gets the http method. 68 HttpMethod method() { return _method; } 69 70 /// Sets the http method. 71 void method(HttpMethod method) 72 { 73 import std.conv; 74 75 _method = method; 76 addAttribute("method", to!string(method)); 77 } 78 } 79 else 80 { 81 /// Gets the http method. 82 string method() { return _method; } 83 84 /// Sets the http method. 85 void method(string method) 86 { 87 _method = method; 88 addAttribute("method", _method); 89 } 90 } 91 } 92 }