From be8b18cf9009b96ce7d6287b0e472962c3a74fd6 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 10 Nov 2017 17:30:20 +0100 Subject: [PATCH] allow to specify a date-format in custom-fields using eg. format=Ymd, as it was possible in 11.1 in len field --- api/src/Etemplate/Widget/Customfields.php | 9 ++++++++- api/src/Etemplate/Widget/Date.php | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index e551e52eb3..7f54978184 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -298,7 +298,14 @@ class Customfields extends Transformer { case 'date': case 'date-time': - $widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s'; + if (!empty($field['values']['format'])) + { + $widget->attrs['dataformat'] = $field['values']['format']; + } + else + { + $widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s'; + } if($field['values']['min']) $widget->attrs['min'] = $field['values']['min']; if($field['values']['max']) $widget->attrs['min'] = $field['values']['max']; break; diff --git a/api/src/Etemplate/Widget/Date.php b/api/src/Etemplate/Widget/Date.php index 3e070dd230..9c0268c2b0 100644 --- a/api/src/Etemplate/Widget/Date.php +++ b/api/src/Etemplate/Widget/Date.php @@ -107,7 +107,7 @@ class Date extends Transformer { if (!$value) return $value; // otherwise we will get current date or 1970-01-01 instead of an empty value - if ($this->attrs['dataformat'] && !is_numeric($value)) + if ($this->attrs['dataformat']) { $date = Api\DateTime::createFromFormat($this->attrs['dataformat'], $value, Api\DateTime::$user_timezone); } @@ -158,6 +158,7 @@ class Date extends Transformer } catch(\Exception $e) { + unset($e); $date = null; $value = ''; // this is not really a user error, but one of the clientside engine @@ -177,7 +178,7 @@ class Date extends Transformer { $valid = (string)$value === '' ? '' : (int)$value; } - + if (!empty($this->attrs['min'])) { if(is_numeric($this->attrs['min']))