aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2025-06-19 16:32:39 +0200
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2025-06-20 10:19:18 +0200
commiteb9f1791ab262797e04ca6dd811d293863dc2114 (patch)
tree65e1a0536c4893f6c72ee79f4e8d0afcc06afc1a
parentff7505895b6611bc014e3a4ed5ef2b054bad793c (diff)
allow date and time data fields entries to be emptied (unless they are required) and fix time datafield input, fixes #5649, fixes #5650
Closes #5649 and #5650 Merge request studip/studip!4267
-rw-r--r--lib/classes/DataFieldDateEntry.php21
-rw-r--r--lib/classes/DataFieldTimeEntry.php30
-rw-r--r--templates/datafields/time.php4
3 files changed, 20 insertions, 35 deletions
diff --git a/lib/classes/DataFieldDateEntry.php b/lib/classes/DataFieldDateEntry.php
index bf7d518..4b8c049 100644
--- a/lib/classes/DataFieldDateEntry.php
+++ b/lib/classes/DataFieldDateEntry.php
@@ -17,16 +17,16 @@ class DataFieldDateEntry extends DataFieldEntry
*
* @param mixed $submitted_value The value from request
*/
- public function setValueFromSubmit($value)
+ public function setValueFromSubmit($submitted_value)
{
- if ($value) {
- $value = trim($value);
- $items = explode(".", $value);
- $value = array_reverse($items);
- $value = array_filter($value);
- $date = implode('-', $value);
- parent::setValueFromSubmit($date);
+ if ($submitted_value) {
+ $submitted_value = trim($submitted_value);
+ $items = explode('.', $submitted_value);
+ $submitted_value = array_reverse($items);
+ $submitted_value = array_filter($submitted_value);
+ $submitted_value = implode('-', $submitted_value);
}
+ parent::setValueFromSubmit($submitted_value);
}
/**
@@ -35,7 +35,7 @@ class DataFieldDateEntry extends DataFieldEntry
* @param bool $entities Should html entities be encoded (defaults to true)
* @return String containg the rendered value
*/
- public function getDisplayValue($entries = true)
+ public function getDisplayValue($entities = true)
{
if ($this->isValid()) {
$value = trim($this->value);
@@ -75,6 +75,7 @@ class DataFieldDateEntry extends DataFieldEntry
return parent::isValid();
}
- return parent::isValid() && strtotime($value) !== false;
+ return parent::isValid()
+ && strtotime($value) !== false;
}
}
diff --git a/lib/classes/DataFieldTimeEntry.php b/lib/classes/DataFieldTimeEntry.php
index 96e5835..2e62c49 100644
--- a/lib/classes/DataFieldTimeEntry.php
+++ b/lib/classes/DataFieldTimeEntry.php
@@ -13,35 +13,19 @@ class DataFieldTimeEntry extends DataFieldEntry
protected $template = 'time.php';
/**
- * Sets the value from a post request
- *
- * @param mixed $submitted_value The value from request
- */
- public function setValueFromSubmit($value)
- {
- if ($value) {
- parent::setValueFromSubmit($value);
- }
- }
-
- /**
- * Checks if the datafield is empty (was not set)
- *
- * @return bool true if empty, else false
- */
- public function isEmpty()
- {
- return $this->getValue() == ':';
- }
-
- /**
* Returns whether the datafield contents are valid
*
* @return boolean indicating whether the datafield contents are valid
*/
public function isValid()
{
- $parts = explode(':', $this->value);
+ $value = trim($this->value);
+
+ if (!$value) {
+ return parent::isValid();
+ }
+
+ $parts = explode(':', $value);
return parent::isValid()
&& $parts[0] >= 0 && $parts[0] <= 24
diff --git a/templates/datafields/time.php b/templates/datafields/time.php
index 0fe3c92..23e52f0 100644
--- a/templates/datafields/time.php
+++ b/templates/datafields/time.php
@@ -8,10 +8,10 @@
<? endif ?>
<div style="white-space: nowrap;">
- <input type="text" name="<?= $name ?>[<?= $model->id ?>][]"
+ <input type="text" name="<?= $name ?>[<?= $model->id ?>]"
value="<?= $value ?>" title="<?= _('Uhrzeit') ?>"
<?= !$entry->isEditable() ? "disabled" : "" ?>
- maxlength="2" class="size-s no-hint has-time-picker"
+ class="size-s no-hint has-time-picker"
<? if ($model->is_required) echo 'required'; ?>>
</div>
</label>