diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst index 4ba88deaf26ab2fca1d78ac4b6b07a0cd4034771..04b738e91f4fe0a1877734c6ff886081e92fb2a0 100644 --- a/extension/Documentation/Manual.rst +++ b/extension/Documentation/Manual.rst @@ -2453,6 +2453,9 @@ See also at specific *FormElement* definitions. +------------------------+--------+----------------------------------------------------------------------------------------------------------+ | showSeconds | string | 0|1 - Shows the seconds on form load. Default: 0 | +------------------------+--------+----------------------------------------------------------------------------------------------------------+ +| timeIsOptional | string | 0|1 - Used for datetime input. 0 (default): Time is required - 1: Entering a time is optional | +| | | (defaults to 00:00:00 if none entered). | ++------------------------+--------+----------------------------------------------------------------------------------------------------------+ | showZero | string | 0|1 - Empty timestamp: '0'(default) - nothing shown, '1' - the string '0000-00-00 00:00:00' is displayed | +------------------------+--------+----------------------------------------------------------------------------------------------------------+ | retype | string | See `input-text`_ | diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index 39d8aa7b9654198dcbaac83bbac0363848dfc1a3..b0c3e8f289e9375426c7a9565b4fa5300314c4bd 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -3144,8 +3144,7 @@ abstract class AbstractBuildForm { $value = Support::convertDateTime($value, $formElement[FE_DATE_FORMAT], $formElement[FE_SHOW_ZERO], $showTime, $formElement[FE_SHOW_SECONDS]); $tmpPattern = $formElement[FE_CHECK_PATTERN]; - $formElement[FE_CHECK_PATTERN] = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement[FE_DATE_FORMAT]); - + $formElement[FE_CHECK_PATTERN] = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement[FE_DATE_FORMAT], $formElement[FE_TIME_IS_OPTIONAL]); switch ($formElement[FE_CHECK_TYPE]) { case SANITIZE_ALLOW_PATTERN: @@ -3187,6 +3186,7 @@ abstract class AbstractBuildForm { $placeholder = $formElement[FE_DATE_FORMAT]; break; case 'datetime': + if ($formElement[FE_TIME_IS_OPTIONAL] == 1) $timePattern = "[$timePattern]"; $placeholder = $formElement[FE_DATE_FORMAT] . ' ' . $timePattern; break; case 'time': diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php index 397e7dc733e4b64d3c0ab2c5c33fa371f7ba6abd..56c8e6ad93b5dafa65fb7a0c1cda0ed25a519527 100644 --- a/extension/qfq/qfq/Constants.php +++ b/extension/qfq/qfq/Constants.php @@ -860,6 +860,7 @@ const FE_PLACEHOLDER = 'placeholder'; const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN const FE_DECIMAL_FORMAT = 'decimalFormat'; // value: 10,2 const FE_SHOW_SECONDS = 'showSeconds'; // value: 0|1 +const FE_TIME_IS_OPTIONAL = 'timeIsOptional'; // value: 0|1 const FE_SHOW_ZERO = 'showZero'; // 0|1 - Used for 'date/datime/time': in case of fe.value='0' shows corresponding '00-00-0000'|'00:00:00' const FE_HIDE_ZERO = 'hideZero'; // 0|1 - In case of fe.value=0|'0', an empty string is shown. const FE_FILE_DESTINATION = 'fileDestination'; // Target pathFilename for an uploaded file. diff --git a/extension/qfq/qfq/helper/Sanitize.php b/extension/qfq/qfq/helper/Sanitize.php index 5babf15db4452bd2c8bc4632c0502114269a36d7..5a71b149ac4d0fc2dacaad29ed29eb8200fc9556 100644 --- a/extension/qfq/qfq/helper/Sanitize.php +++ b/extension/qfq/qfq/helper/Sanitize.php @@ -105,7 +105,7 @@ class Sanitize { case SANITIZE_ALLOW_EMAIL: case SANITIZE_ALLOW_ALNUMX: case SANITIZE_ALLOW_ALLBUT: - $pattern = self::$sanitizePattern[$checkType]; + $pattern = self::$sanitizePattern[$checkType]; break; default: diff --git a/extension/qfq/qfq/helper/Support.php b/extension/qfq/qfq/helper/Support.php index bf12ef735b6a4f26f4558c355d72aa829db13442..a8a024a8ca6c72076873fc84071f406c48655da7 100644 --- a/extension/qfq/qfq/helper/Support.php +++ b/extension/qfq/qfq/helper/Support.php @@ -258,9 +258,9 @@ class Support { } /** - * Search for the parameter $needle in $haystack. The arguments has to be seperated by ','. + * Search for the parameter $needle in $haystack. The arguments has to be separated by ','. * - * Returns false if not found or index of found place. Be carefull: use unary operator to compare for 'false' + * Returns false if not found or index of found place. Be careful: use unary operator to compare for 'false' * * @param string $needle * @param string $haystack @@ -367,11 +367,12 @@ class Support { /** * @param string $type date | datetime | time * @param string $format FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN + * @param string $timeIsOptional * * @return string * @throws UserFormException */ - public static function dateTimeRegexp($type, $format) { + public static function dateTimeRegexp($type, $format, $timeIsOptional = '0') { if ($format === FORMAT_DATE_GERMAN) { // yyyy-mm-dd | 0000-00-00 @@ -389,7 +390,10 @@ class Support { $pattern = $date; break; case 'datetime': - $pattern = $date . ' ' . $time; + if ($timeIsOptional == '1') + $pattern = $date . '( ' . $time . ')?'; + else + $pattern = $date . ' ' . $time; break; case 'time': $pattern = $time; @@ -721,6 +725,7 @@ class Support { // Some Defaults self::setIfNotSet($formElement, FE_SHOW_SECONDS, '0'); + self::setIfNotSet($formElement, FE_TIME_IS_OPTIONAL, '0'); self::setIfNotSet($formElement, FE_SHOW_ZERO, '0'); self::setIfNotSet($formElement, FE_HIDE_ZERO, '0'); self::setIfNotSet($formElement, FE_DATE_FORMAT, $store->getVar(SYSTEM_DATE_FORMAT, STORE_SYSTEM)); diff --git a/extension/qfq/qfq/store/FillStoreForm.php b/extension/qfq/qfq/store/FillStoreForm.php index 87331cf7b611738eaa50dea3fbaeeb2ec511eee2..cfd8ffcde2981cbbd16980bb82824e2814f99da4 100644 --- a/extension/qfq/qfq/store/FillStoreForm.php +++ b/extension/qfq/qfq/store/FillStoreForm.php @@ -312,7 +312,7 @@ class FillStoreForm { */ public function doDateTime(array &$formElement, $value) { - $regexp = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement[FE_DATE_FORMAT]); + $regexp = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement[FE_DATE_FORMAT], $formElement[FE_TIME_IS_OPTIONAL]); if (1 !== preg_match('/' . $regexp . '/', $value, $matches)) { $placeholder = Support::getDateTimePlaceholder($formElement);