2 declare(strict_types = 1);
59 parent::initializeArguments();
60 $this->registerTagAttribute(
'size',
'int',
'The size of the input field');
61 $this->registerTagAttribute(
'placeholder',
'string',
'Specifies a short hint that describes the expected value of an input element');
62 $this->registerArgument(
'errorClass',
'string',
'CSS class to set if there are errors for this ViewHelper',
false,
'f3-form-error');
63 $this->registerArgument(
'initialDate',
'string',
'Initial date (@see http://www.php.net/manual/en/datetime.formats.php for supported formats)');
64 $this->registerArgument(
'enableDatePicker',
'bool',
'Enable the Datepicker',
false,
true);
65 $this->registerArgument(
'previewMode',
'bool',
'Preview mde flag',
true,
false);
66 $this->registerArgument(
'dateFormat',
'string',
'The date format',
false,
'Y-m-d');
67 $this->registerUniversalTagAttributes();
77 $enableDatePicker = $this->arguments[
'enableDatePicker'];
78 $dateFormat = $this->arguments[
'dateFormat'];
79 $previewMode = (bool)$this->arguments[
'previewMode'];
80 $placeholder = $this->arguments[
'additionalAttributes'][
'placeholder'] ?? $this->arguments[
'placeholder'];
85 $this->tag->addAttribute(
'type',
'text');
86 $this->tag->addAttribute(
'name', $name .
'[date]');
88 if ($this->hasArgument(
'id')) {
89 $id = $this->arguments[
'id'];
91 $id =
'field' . md5(uniqid());
94 if (empty($placeholder)) {
95 $this->tag->addAttribute(
'placeholder', $dateFormat);
98 if ($enableDatePicker) {
99 $this->tag->addAttribute(
'readonly',
'readonly');
106 if ($date !==
null) {
107 $this->tag->addAttribute(
'value', $date->format($dateFormat));
110 $this->tag->addAttribute(
'id', $id);
114 $content .= $this->tag->render();
115 $content .=
'<input type="hidden" name="' . htmlspecialchars($name) .
'[dateFormat]" value="' . htmlspecialchars($dateFormat) .
'" />';
126 $formRuntime = $this->renderingContext
127 ->getViewHelperVariableContainer()
128 ->get(RenderRenderableViewHelper::class,
'formRuntime');
130 $formState = $formRuntime->getFormState();
132 $date = $formRuntime[$this->arguments[
'property']];
133 if ($date instanceof \DateTime) {
136 if ($date !==
null) {
137 $date = $this->propertyMapper->convert($date,
'DateTime');
138 if (!$date instanceof \DateTime) {
143 if ($this->hasArgument(
'initialDate')) {
144 return new \DateTime($this->arguments[
'initialDate']);
168 return strtr($dateFormat, $replacements);
178 'ext_form_datepicker-' . $uniqueIdentifier,
179 'if ("undefined" !== typeof $) {
181 $("#' . $uniqueIdentifier .
'").datepicker({
182 dateFormat: "' . $datePickerDateFormat .
'"
183 }).on("keydown", function(e) {
184 // By using "backspace" or "delete", you can clear the datepicker again.
185 if(e.keyCode == 8 || e.keyCode == 46) {
187 $.datepicker._clearDate(this);
201 return GeneralUtility::makeInstance(PageRenderer::class);