Skip to content

Commit

Permalink
Support for datetime-local
Browse files Browse the repository at this point in the history
Support HTML datetime-local, allows usage of a native date/time picker. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

The input has to have a type of `datetime-local`
  • Loading branch information
ynamite authored Oct 16, 2024
1 parent ada7342 commit aad08e9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/yform/value/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class rex_yform_value_datetime extends rex_yform_value_abstract
public function preValidateAction(): void
{
$value = $this->getValue();

if ('' == $this->getValue() && $this->params['main_id'] < 1) {
if (1 == $this->getElement('current_date')) {
$value = date(rex_sql::FORMAT_DATETIME);
Expand All @@ -36,7 +37,11 @@ public function preValidateAction(): void
$second = (int) ($value['second'] ?? 0);
} else {
$value = (string) $value;
$value = explode(' ', $value);
$localTimeTest = explode(' ', $value);
if (2 != count($localTimeTest)) {
$localTimeTest = explode('T', $value);
}
$value = $localTimeTest;
if (2 == count($value)) {
$date = explode('-', (string) $value[0]);
$year = (int) ($date[0] ?? 0);
Expand Down Expand Up @@ -64,7 +69,11 @@ public function enterObject()
$second = (int) ($value['second'] ?? 0);
} else {
$value = (string) $value;
$value = explode(' ', $value);
$localTimeTest = explode(' ', $value);
if (2 != count($localTimeTest)) {
$localTimeTest = explode('T', $value);
}
$value = $localTimeTest;
if (2 == count($value)) {
$date = explode('-', (string) $value[0]);
$year = (int) ($date[0] ?? 0);
Expand Down Expand Up @@ -182,7 +191,8 @@ public static function getSearchField($params)
'name' => $params['field']->getName(),
'label' => $params['field']->getLabel(),
'notice' => rex_i18n::msg('yform_values_date_search_notice', $format),
'attributes' => '{"data-yform-tools-datetimerangepicker":"' . $format . '"}', ]);
'attributes' => '{"data-yform-tools-datetimerangepicker":"' . $format . '"}',
]);
}

public static function getSearchFilter($params)
Expand Down

0 comments on commit aad08e9

Please sign in to comment.