add code for datetime-local input elements
[php-utility-classes.git] / classes / document.php-class
index ebde6ec965f8ec52f16bbfaa6f40610519351e7e..c48415fd22e66aa26f09143a33c6e351d1639891 100755 (executable)
@@ -89,6 +89,10 @@ class ExtendedDocument extends DOMDocument {
   //   appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params)
   //     returns the new child
   //
   //   appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params)
   //     returns the new child
   //
+  // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
+  //   appends an ExtendedDocument::createElementInputDateTime() as a child of this document (see there for params)
+  //     returns the new child
+  //
   // public function appendInputColor($name, [$id], [$value])
   //   appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params)
   //     returns the new child
   // public function appendInputColor($name, [$id], [$value])
   //   appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params)
   //     returns the new child
@@ -226,6 +230,10 @@ class ExtendedDocument extends DOMDocument {
   //   returns an ExtendedElement that is an HTML <input> of type 'time' with the given name,
   //   and optionally id, min, max, and value
   //
   //   returns an ExtendedElement that is an HTML <input> of type 'time' with the given name,
   //   and optionally id, min, max, and value
   //
+  // public function createElementInputDateTime($name, [$id], [$min], [$max], [$value])
+  //   returns an ExtendedElement that is an HTML <input> of type 'datetime-local' with the given name,
+  //   and optionally id, min, max, and value
+  //
   // public function createElementInputColor($name, [$id], [$value])
   //   returns an ExtendedElement that is an HTML <input> of type 'color' with the given name,
   //   and optionally id and value
   // public function createElementInputColor($name, [$id], [$value])
   //   returns an ExtendedElement that is an HTML <input> of type 'color' with the given name,
   //   and optionally id and value
@@ -383,6 +391,9 @@ class ExtendedDocument extends DOMDocument {
   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
     return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value));
   }
   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
     return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value));
   }
+  public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+    return $this->appendChild($this->createElementInputDateTime($name, $id, $min, $max, $value));
+  }
   public function appendInputColor($name, $id = null, $value = null) {
     return $this->appendChild($this->createElementInputColor($name, $id, $value));
   }
   public function appendInputColor($name, $id = null, $value = null) {
     return $this->appendChild($this->createElementInputColor($name, $id, $value));
   }
@@ -613,6 +624,17 @@ class ExtendedDocument extends DOMDocument {
     return $timefield;
   }
 
     return $timefield;
   }
 
+  public function createElementInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+    $dtfield = $this->createElement('input');
+    $dtfield->setAttribute('type', 'datetime-local');
+    if (!is_null($id)) { $dtfield->setAttribute('id', $id); }
+    $dtfield->setAttribute('name', $name);
+    if (!is_null($min)) { $dtfield->setAttribute('min', $min); }
+    if (!is_null($max)) { $dtfield->setAttribute('max', $max); }
+    if (!is_null($value)) { $dtfield->setAttribute('value', str_replace(' ', 'T', $value, 1)); }
+    return $dtfield;
+  }
+
   public function createElementInputColor($name, $id = null, $value = null) {
     $colfield = $this->createElement('input');
     $colfield->setAttribute('type', 'color');
   public function createElementInputColor($name, $id = null, $value = null) {
     $colfield = $this->createElement('input');
     $colfield->setAttribute('type', 'color');
@@ -687,10 +709,12 @@ class ExtendedDocument extends DOMDocument {
 
   public function createElementOption($key, $desc, $selected = false) {
     $option = $this->createElement('option', $desc);
 
   public function createElementOption($key, $desc, $selected = false) {
     $option = $this->createElement('option', $desc);
-    if ($key) {
+    if (is_numeric($key) || is_string($key)) {
       $option->setAttribute('value', $key);
     }
       $option->setAttribute('value', $key);
     }
-    if ($selected) { $option->setAttribute('selected', ''); }
+    if ($selected) {
+      $option->setAttribute('selected', '');
+    }
     return $option;
   }
 
     return $option;
   }
 
@@ -813,6 +837,10 @@ class ExtendedElement extends DOMElement {
   //   appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params)
   //     returns the new child
   //
   //   appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params)
   //     returns the new child
   //
+  // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
+  //   appends an ExtendedDocument::createElementInputDateTime() as a child of this element (see there for params)
+  //     returns the new child
+  //
   // public function appendInputColor($name, [$id], [$value])
   //   appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params)
   //
   // public function appendInputColor($name, [$id], [$value])
   //   appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params)
   //
@@ -961,6 +989,9 @@ class ExtendedElement extends DOMElement {
   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
   }
   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
   }
+  public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+    return $this->appendChild($this->ownerDocument->createElementInputDateTime($name, $id, $min, $max, $value));
+  }
   public function appendInputColor($name, $id = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
   }
   public function appendInputColor($name, $id = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
   }
@@ -1112,6 +1143,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   //   appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params)
   //     returns the new child
   //
   //   appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params)
   //     returns the new child
   //
+  // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
+  //   appends an ExtendedDocument::createElementInputDateTime() as a child of this fragment (see there for params)
+  //     returns the new child
+  //
   // public function appendInputColor($name, [$id], [$value])
   //   appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params)
   //
   // public function appendInputColor($name, [$id], [$value])
   //   appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params)
   //
@@ -1250,6 +1285,9 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
   }
   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
   }
+  public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+    return $this->appendChild($this->ownerDocument->createElementInputDateTime($name, $id, $min, $max, $value));
+  }
   public function appendInputColor($name, $id = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
   }
   public function appendInputColor($name, $id = null, $value = null) {
     return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
   }