Commits

Robert Clipsham committed 101d487

Fixed HTML5 validation for forms.

  • Participants
  • Parent commits 8606678

Comments (0)

Files changed (4)

     {
         ret ~= `public Field ` ~ type ~ `(char[] label, char[] name, char[] value=null)
                 {
-                    if (label !is null && name !is null)
+                    auto el = mForm.input.attr("type", toLower("` ~ type ~ `"c));
+                    if (label !is null)
                     {
                         mForm.label.attr("for", name).content = label;
+                        el.attr("id", name);
                     }
-                    auto el = mForm.input.attr("type", toLower("` ~ type ~ `"c));
-                    if (name !is null)
-                    {
-                         el.attr("name", name);
-                    }
+                    el.attr("name", name);
                     if (value !is null)
                     {
                         el.attr("value", value);
     public Field textArea(char[] label, char[] name, char[] value=null)
     {
         mForm.label.attr("for", name).content = label;
-        mForm.textarea.attr("name", name).content = value;
+        mForm.textarea.attr("id", name).content = value;
         mFields ~= new Field(label, name);
         return mFields[$-1];
     }

serenity/Html5Printer.d

 package import serenity.HtmlDocument;
 import serenity.DocumentPrinter;
 
+import tango.core.Array : find;
 import tango.text.convert.Format;
 
+char[][] noClosingTag;
+
+static this()
+{
+    // TODO Complete this list
+    noClosingTag = [ "input", "meta" ];
+}
+
 class Html5Printer //: DocumentPrinter
 {
     void print(HtmlDocument doc, void delegate(char[][]...) dg)
                 {
                     print(child, dg);
                 }
-                dg("</", doc.typeName(), ">");
+                if (noClosingTag.find(doc.typeName()) == noClosingTag.length)
+                {
+                    dg("</", doc.typeName(), ">");
+                }
                 break;
         }
     }

serenity/HtmlDocument.d

         doctype();
         auto html = html();
         html.head.title.content = title;
+        html.head.meta.attr("charset", "UTF-8");
         html.body_();
         return this;
     }

serenity/HtmlPrinter.d

 {
     void print(HtmlDocument doc, void delegate(char[][]...) dg)
     {
-        // TODO Wrap HTML5 elements in <div>'s
+        // TODO * Wrap HTML5 elements in <div>'s
+        //      * <meta charset=""> to <meta http-equiv="Content-type"...>
         super.print(doc, dg);
     }
 }