Commit ce5793b8 authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #5308 - TimeIsOptional parameter

parent f9cbc848
...@@ -2453,6 +2453,9 @@ See also at specific *FormElement* definitions. ...@@ -2453,6 +2453,9 @@ See also at specific *FormElement* definitions.
+------------------------+--------+----------------------------------------------------------------------------------------------------------+ +------------------------+--------+----------------------------------------------------------------------------------------------------------+
| showSeconds | string | 0|1 - Shows the seconds on form load. Default: 0 | | 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 | | 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`_ | | retype | string | See `input-text`_ |
......
...@@ -3142,8 +3142,7 @@ abstract class AbstractBuildForm { ...@@ -3142,8 +3142,7 @@ abstract class AbstractBuildForm {
$value = Support::convertDateTime($value, $formElement[FE_DATE_FORMAT], $formElement[FE_SHOW_ZERO], $showTime, $formElement[FE_SHOW_SECONDS]); $value = Support::convertDateTime($value, $formElement[FE_DATE_FORMAT], $formElement[FE_SHOW_ZERO], $showTime, $formElement[FE_SHOW_SECONDS]);
$tmpPattern = $formElement[FE_CHECK_PATTERN]; $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]) { switch ($formElement[FE_CHECK_TYPE]) {
case SANITIZE_ALLOW_PATTERN: case SANITIZE_ALLOW_PATTERN:
...@@ -3185,6 +3184,7 @@ abstract class AbstractBuildForm { ...@@ -3185,6 +3184,7 @@ abstract class AbstractBuildForm {
$placeholder = $formElement[FE_DATE_FORMAT]; $placeholder = $formElement[FE_DATE_FORMAT];
break; break;
case 'datetime': case 'datetime':
if ($formElement[FE_TIME_IS_OPTIONAL] == 1) $timePattern = "[$timePattern]";
$placeholder = $formElement[FE_DATE_FORMAT] . ' ' . $timePattern; $placeholder = $formElement[FE_DATE_FORMAT] . ' ' . $timePattern;
break; break;
case 'time': case 'time':
......
...@@ -860,6 +860,7 @@ const FE_PLACEHOLDER = 'placeholder'; ...@@ -860,6 +860,7 @@ const FE_PLACEHOLDER = 'placeholder';
const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
const FE_DECIMAL_FORMAT = 'decimalFormat'; // value: 10,2 const FE_DECIMAL_FORMAT = 'decimalFormat'; // value: 10,2
const FE_SHOW_SECONDS = 'showSeconds'; // value: 0|1 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_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_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. const FE_FILE_DESTINATION = 'fileDestination'; // Target pathFilename for an uploaded file.
......
...@@ -105,7 +105,7 @@ class Sanitize { ...@@ -105,7 +105,7 @@ class Sanitize {
case SANITIZE_ALLOW_EMAIL: case SANITIZE_ALLOW_EMAIL:
case SANITIZE_ALLOW_ALNUMX: case SANITIZE_ALLOW_ALNUMX:
case SANITIZE_ALLOW_ALLBUT: case SANITIZE_ALLOW_ALLBUT:
$pattern = self::$sanitizePattern[$checkType]; $pattern = self::$sanitizePattern[$checkType];
break; break;
default: default:
......
...@@ -258,9 +258,9 @@ class Support { ...@@ -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 $needle
* @param string $haystack * @param string $haystack
...@@ -367,11 +367,12 @@ class Support { ...@@ -367,11 +367,12 @@ class Support {
/** /**
* @param string $type date | datetime | time * @param string $type date | datetime | time
* @param string $format FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN * @param string $format FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
* @param string $timeIsOptional
* *
* @return string * @return string
* @throws UserFormException * @throws UserFormException
*/ */
public static function dateTimeRegexp($type, $format) { public static function dateTimeRegexp($type, $format, $timeIsOptional = '0') {
if ($format === FORMAT_DATE_GERMAN) { if ($format === FORMAT_DATE_GERMAN) {
// yyyy-mm-dd | 0000-00-00 // yyyy-mm-dd | 0000-00-00
...@@ -389,7 +390,10 @@ class Support { ...@@ -389,7 +390,10 @@ class Support {
$pattern = $date; $pattern = $date;
break; break;
case 'datetime': case 'datetime':
$pattern = $date . ' ' . $time; if ($timeIsOptional == '1')
$pattern = $date . '( ' . $time . ')?';
else
$pattern = $date . ' ' . $time;
break; break;
case 'time': case 'time':
$pattern = $time; $pattern = $time;
...@@ -721,6 +725,7 @@ class Support { ...@@ -721,6 +725,7 @@ class Support {
// Some Defaults // Some Defaults
self::setIfNotSet($formElement, FE_SHOW_SECONDS, '0'); 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_SHOW_ZERO, '0');
self::setIfNotSet($formElement, FE_HIDE_ZERO, '0'); self::setIfNotSet($formElement, FE_HIDE_ZERO, '0');
self::setIfNotSet($formElement, FE_DATE_FORMAT, $store->getVar(SYSTEM_DATE_FORMAT, STORE_SYSTEM)); self::setIfNotSet($formElement, FE_DATE_FORMAT, $store->getVar(SYSTEM_DATE_FORMAT, STORE_SYSTEM));
......
...@@ -312,7 +312,7 @@ class FillStoreForm { ...@@ -312,7 +312,7 @@ class FillStoreForm {
*/ */
public function doDateTime(array &$formElement, $value) { 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)) { if (1 !== preg_match('/' . $regexp . '/', $value, $matches)) {
$placeholder = Support::getDateTimePlaceholder($formElement); $placeholder = Support::getDateTimePlaceholder($formElement);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment