From c1792eda53eaa5a0864fdd92d57d3bd0e233a8cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Setni=C4=8Dka?= <setnicka@seznam.cz>
Date: Sat, 20 Nov 2021 20:58:54 +0100
Subject: [PATCH] =?UTF-8?q?Table:=20P=C5=99id=C3=A1n=C3=AD=20CellInput?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mo/web/table.py | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/mo/web/table.py b/mo/web/table.py
index 50a2b0d2..0404908c 100644
--- a/mo/web/table.py
+++ b/mo/web/table.py
@@ -71,22 +71,35 @@ class CellLink(Cell):
         return a + '>' + escape(self.text) + '</a>' + str(self.html_suffix)
 
 
-class CellCheckbox(Cell):
+class CellInput(Cell):
     name: str
     value: str
-    checked: bool
+    type: str
+    attrs: Dict[str, Optional[str]]
 
-    def __init__(self, name: str, value: str, checked: bool = False):
+    def __init__(self, name: str, value: str, type: str = "text", attrs: Dict[str, Optional[str]] = {}):
         Cell.__init__(self, "")
         self.name = name
         self.value = value
-        self.checked = checked
+        self.type = type
+        self.attrs = attrs
 
     def to_html(self) -> str:
-        ch = f'<td><input type="checkbox" name="{self.name}" value="{self.value}"'
-        if self.checked:
-            ch += ' checked'
-        return ch + '>'
+        out = f'<td><input type="{self.type}" name="{self.name}" value="{self.value}"'
+        for (attr, value) in self.attrs.items():
+            out += f' {attr}'
+            if value is not None:
+                out += '=' + escape(value)
+        return out + '>'
+
+
+class CellCheckbox(CellInput):
+    def __init__(self, name: str, value: str, checked: bool = False):
+        attrs = {}
+        if checked:
+            attrs['checked'] = None
+        CellInput.__init__(self, name, value, "checkbox", attrs)
+
 
 class CellMarkup(Cell):
     text: str
-- 
GitLab