diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php
index e2c71ba9814e4a74f774aefee5bf4c2e95cafcde..b5b12ef36cb38a7f69387ff54881d7bfb2868a3c 100644
--- a/extension/qfq/qfq/AbstractBuildForm.php
+++ b/extension/qfq/qfq/AbstractBuildForm.php
@@ -662,7 +662,7 @@ abstract class AbstractBuildForm {
 
         // date/datetime
         if ($maxLength !== false) {
-            if (is_numeric($formElement['maxLength'])) {
+            if (is_numeric($formElement['maxLength'] && $formElement['maxLength'] != '0')) {
                 if ($formElement['maxLength'] > $maxLength) {
                     $formElement['maxLength'] = $maxLength;
                 }
@@ -691,6 +691,9 @@ abstract class AbstractBuildForm {
             case 'time': // hh:mm:ss
                 return 8;
             default:
+                if (substr($typeSpec, 0, 4) === 'set(' || substr($typeSpec, 0, 5) === 'enum(') {
+                    return $this->maxLengthSetEnum($typeSpec);
+                }
                 break;
         }
 
@@ -703,6 +706,29 @@ abstract class AbstractBuildForm {
         return false;
     }
 
+    /**
+     * Get the strlen of the longest element in enum('val1','val2',...,'valn') or set('val1','val2',...,'valn')
+     *
+     * @param string $typeSpec
+     * @return int
+     */
+    private function maxLengthSetEnum($typeSpec) {
+        $startPos = (substr($typeSpec, 0, 4) === 'set(') ? 4 : 5;
+        $max = 0;
+
+        $valueList = substr($typeSpec, $startPos, strlen($typeSpec) - $startPos - 1);
+        $valueArr = explode(',', $valueList);
+        foreach ($valueArr as $value) {
+            $value = trim($value, "'");
+            $len = strlen($value);
+            if ($len > $max) {
+                $max = $len;
+            }
+        }
+
+        return $max;
+    }
+
     /**
      * Builds a HTML attribute list, based on  $attributeList.
      *
diff --git a/extension/qfq/qfq/helper/Support.php b/extension/qfq/qfq/helper/Support.php
index 60fd97cf807a1f79463d2e61f5071e7f9f985991..6bf61440096103f7d2bf86df9e9488174f94913c 100644
--- a/extension/qfq/qfq/helper/Support.php
+++ b/extension/qfq/qfq/helper/Support.php
@@ -90,8 +90,21 @@ class Support {
      * @return string
      */
     public static function doAttribute($type, $value, $flagOmitEmpty = true) {
-        if ($flagOmitEmpty && $value === "")
+        if ($flagOmitEmpty && $value === "") {
             return '';
+        }
+
+        switch ($type) {
+            case 'size':
+            case 'maxlength':
+                // empty or '0' for attributes of type 'size' or 'maxlenght' result in unsuable input elements: skip this.
+                if ($value === '' || $value == 0) {
+                    return '';
+                }
+                break;
+            default:
+                break;
+        }
 
         return $type . '="' . trim($value) . '" ';
     }