From cac1df2523f5118c5bc2783d3ed806015508ece6 Mon Sep 17 00:00:00 2001 From: "James (DPC)" <69664712+JamesDPC@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:30:53 +1100 Subject: [PATCH] Add date picker component via extension to DateField, with relevant templates Ref #89 --- src/Extensions/DateFieldExtension.php | 57 +++++++++++++++++++ .../NSWDPC/Waratah/Forms/DateField.ss | 55 ++++++++++++++++++ .../NSWDPC/Waratah/Forms/DateField_holder.ss | 19 +++++++ .../templates/nswds/Includes/DatePicker.ss | 1 + 4 files changed, 132 insertions(+) create mode 100644 src/Extensions/DateFieldExtension.php create mode 100644 themes/nswds/templates/NSWDPC/Waratah/Forms/DateField.ss create mode 100644 themes/nswds/templates/NSWDPC/Waratah/Forms/DateField_holder.ss create mode 100644 themes/nswds/templates/nswds/Includes/DatePicker.ss diff --git a/src/Extensions/DateFieldExtension.php b/src/Extensions/DateFieldExtension.php new file mode 100644 index 00000000..b7dc2bf9 --- /dev/null +++ b/src/Extensions/DateFieldExtension.php @@ -0,0 +1,57 @@ +setAttribute('data-min-date','31/12/2020') + * $field->setAttribute('data-min-date','31/12/2022') + * $field->setAttribute('data-dates-disabled','20/01/2022 01/04/2021') + * + * This extension does not (yet) implement the picker on the DateCompositeField from the + * nswdpc/silverstripe-datetime-inputs module + */ +class DateFieldExtension extends Extension +{ + + /** + * Update the available attributes for the input + */ + public function updateAttributes(&$attributes) { + $attributes['autocomplete'] = 'off'; + $attributes['type'] = 'text';// component blocks native browser type + if(!isset($attributes['class'])) { + $attributes['class'] = ''; + } + $attributes['class'] .= ' nsw-form__input js-date-input__text'; + $attributes['class'] = trim($attributes['class']); + } + + /** + * Update render templates + */ + public function onBeforeRenderHolder($context, $properties) { + $this->owner->setInputType('text'); + $this->owner->setTemplate('NSWDPC/Waratah/Forms/DateField'); + $this->owner->setFieldHolderTemplate('NSWDPC/Waratah/Forms/DateField_holder'); + } + +} diff --git a/themes/nswds/templates/NSWDPC/Waratah/Forms/DateField.ss b/themes/nswds/templates/NSWDPC/Waratah/Forms/DateField.ss new file mode 100644 index 00000000..8fb0c21e --- /dev/null +++ b/themes/nswds/templates/NSWDPC/Waratah/Forms/DateField.ss @@ -0,0 +1,55 @@ +
+ + + +
+ + diff --git a/themes/nswds/templates/NSWDPC/Waratah/Forms/DateField_holder.ss b/themes/nswds/templates/NSWDPC/Waratah/Forms/DateField_holder.ss new file mode 100644 index 00000000..23acffe3 --- /dev/null +++ b/themes/nswds/templates/NSWDPC/Waratah/Forms/DateField_holder.ss @@ -0,0 +1,19 @@ +
+ +
+ + <% if $Title %><% end_if %> + + <% include NSWDPC/Waratah/Forms/Description %> + +
+ {$Field} +
+ + <% include nswds/FormFieldMessage FormFieldMessage_IsCompact=1, FormFieldMessage_Message=$Message, FormFieldMessage_MessageType=$MessageType, FormFieldMessage_MessageCast=$MessageCast %> + + <% include NSWDPC/Waratah/Forms/RightTitle %> + +
+ +
diff --git a/themes/nswds/templates/nswds/Includes/DatePicker.ss b/themes/nswds/templates/nswds/Includes/DatePicker.ss new file mode 100644 index 00000000..35c56833 --- /dev/null +++ b/themes/nswds/templates/nswds/Includes/DatePicker.ss @@ -0,0 +1 @@ +<%-- this component is implemented via the DateFieldExtension extension to DateField --%>