From 3c77276b2434a935bf9833b1da9abf2d235b07cf Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Fri, 26 Jan 2024 11:35:50 +0100 Subject: [PATCH 1/9] Allow user to set digits limitations to numeric fields --- assets/js/frontend/frontend.ts | 4 ++-- includes/lib/msf-blocks/numeric/msf-block-numeric.class.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/js/frontend/frontend.ts b/assets/js/frontend/frontend.ts index abcb74a..d07a708 100644 --- a/assets/js/frontend/frontend.ts +++ b/assets/js/frontend/frontend.ts @@ -600,13 +600,13 @@ jQuery(document).ready(function ($) { return false; } if (minimum !== undefined && parseInt(minimum, 10) !== NaN) { - if (parseInt(minimum, 10) > numericValue) { + if (parseInt(minimum, 10) > numeric.length) { $element.addClass('fw-block-invalid'); return false; } } if (maximum !== undefined && parseInt(maximum, 10) !== NaN) { - if (parseInt(maximum, 10) < numericValue) { + if (parseInt(maximum, 10) < numeric.length) { $element.addClass('fw-block-invalid'); return false; } diff --git a/includes/lib/msf-blocks/numeric/msf-block-numeric.class.php b/includes/lib/msf-blocks/numeric/msf-block-numeric.class.php index d853535..6939a97 100644 --- a/includes/lib/msf-blocks/numeric/msf-block-numeric.class.php +++ b/includes/lib/msf-blocks/numeric/msf-block-numeric.class.php @@ -94,7 +94,7 @@ public static function from_aa($aa , $current_version, $serialized_version) { } if (strlen($minimum) > 0 && strlen($maximum) > 0) { - if (intval($minimum) >= intval($maximum)) { + if (intval($minimum) > intval($maximum)) { $maximum = strval(intval($minimum) + 1); } } From 62bae7aa42fd0288cde9644586173ddba7618f8b Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Fri, 26 Jan 2024 14:08:21 +0100 Subject: [PATCH 2/9] Start adding 'allow future dates' checkbox to date fields --- assets/js/backend/wizard-admin.ts | 2 ++ includes/admin/msf-admin.class.php | 1 + 2 files changed, 3 insertions(+) diff --git a/assets/js/backend/wizard-admin.ts b/assets/js/backend/wizard-admin.ts index d67fc90..ee5b670 100644 --- a/assets/js/backend/wizard-admin.ts +++ b/assets/js/backend/wizard-admin.ts @@ -253,6 +253,7 @@ declare var wp: any; dateHtml += ''; dateHtml += '
'; dateHtml += ''; + dateHtml += ''; return dateHtml; } @@ -662,6 +663,7 @@ declare var wp: any; text['label'] = $text.find('.fw-text-label').val(); text['format'] = $text.find('.fw-date-format').val(); text['required'] = $text.find('.fw-required').prop('checked'); + text['allowfuturedates'] = $text.find('.fw-allowfuturedates').prop('checked'); } function getTextareaData($text, text) { diff --git a/includes/admin/msf-admin.class.php b/includes/admin/msf-admin.class.php index 896178a..a07684a 100755 --- a/includes/admin/msf-admin.class.php +++ b/includes/admin/msf-admin.class.php @@ -86,6 +86,7 @@ public static function get_translation() { 'label' => __('Label', 'multi-step-form'), 'multifile' => __('Multiple Files', 'multi-step-form'), 'dateformat' => __('Date Format', 'multi-step-form'), + 'allowfuturedates' => __('Allow future dates', 'multi-step-form'), 'required' => __('Required', 'multi-step-form'), 'radio' => array( 'header' => __('Header', 'multi-step-form'), From 8d8969fbf70c9e6b4e15fb27731bcf3af6622939 Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Tue, 30 Jan 2024 20:54:44 +0100 Subject: [PATCH 3/9] Expand date block with 'allowfuturedates' attribute --- includes/lib/msf-blocks/date/msf-block-date.class.php | 10 +++++++--- includes/lib/msf-wizard-service.class.php | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/includes/lib/msf-blocks/date/msf-block-date.class.php b/includes/lib/msf-blocks/date/msf-block-date.class.php index e0a4390..65c3d2f 100644 --- a/includes/lib/msf-blocks/date/msf-block-date.class.php +++ b/includes/lib/msf-blocks/date/msf-block-date.class.php @@ -12,6 +12,7 @@ class Mondula_Form_Wizard_Block_Date extends Mondula_Form_Wizard_Block { private $_label; private $_required; private $_format; + private $_allowfuturedates; protected static $type = "fw-date"; @@ -21,7 +22,7 @@ class Mondula_Form_Wizard_Block_Date extends Mondula_Form_Wizard_Block { * @param boolean $required The If true, Input for this field is required. * @param string $format The Format the Date will be shown in. */ - public function __construct ($label, $required, $format) { + public function __construct ($label, $required, $format, $allowfuturedates = true) { $this->_label = $label; $this->_required = $required; if (!empty($format)) { @@ -29,6 +30,7 @@ public function __construct ($label, $required, $format) { } else { $this->_format = 'yy-mm-dd'; } + $this->_allowfuturedates = $allowfuturedates; } public function render($ids) { @@ -50,7 +52,8 @@ public function as_aa() { 'type' => 'date', 'label' => $this->_label, 'required' => $this->_required, - 'format' => $this->_format + 'format' => $this->_format, + 'allowfuturedates' => $this->_allowfuturedates ); } @@ -58,7 +61,8 @@ public static function from_aa($aa , $current_version, $serialized_version) { $label = $aa['label']; $required = $aa['required']; $format = $aa['format']; - return new Mondula_Form_Wizard_Block_Date($label, $required, $format); + $allowfuturedates = $aa['allowfuturedates']; + return new Mondula_Form_Wizard_Block_Date($label, $required, $format, $allowfuturedates); } public static function addType($types) { diff --git a/includes/lib/msf-wizard-service.class.php b/includes/lib/msf-wizard-service.class.php index 3397e2e..49cf053 100755 --- a/includes/lib/msf-wizard-service.class.php +++ b/includes/lib/msf-wizard-service.class.php @@ -22,6 +22,7 @@ public function get_by_id($id) { $row = $this->_repository->find_by_id($id); if ($row) { + file_put_contents('test.txt', var_export(Mondula_Form_Wizard_Wizard::from_aa(json_decode($row->json, true), $this->_plugin_version, $row->version), true)); return Mondula_Form_Wizard_Wizard::from_aa(json_decode($row->json, true), $this->_plugin_version, $row->version); } else { return null; From 06aeff1f1e9381ca5dfaf5851b20c1e5dd28931b Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Wed, 31 Jan 2024 09:32:54 +0100 Subject: [PATCH 4/9] Fail date validation when chosen date is in the future and that is not allowed --- assets/js/frontend/frontend.ts | 29 +++++++++++++++++++ .../msf-blocks/date/msf-block-date.class.php | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/assets/js/frontend/frontend.ts b/assets/js/frontend/frontend.ts index d07a708..c711d3e 100644 --- a/assets/js/frontend/frontend.ts +++ b/assets/js/frontend/frontend.ts @@ -629,6 +629,35 @@ jQuery(document).ready(function ($) { $element.addClass('fw-block-invalid'); return false; } else { + const allowFutureDates = $element[0].getAttribute('data-allowfuturedates') === 'true' + if (!allowFutureDates) { + const input = $element[0].querySelector('.fw-datepicker-here') + const dateFormat = input.getAttribute('data-dateformat') + let day, month, year + switch (dateFormat) { + case 'yy-mm-dd': + [year, month, day] = input.value.split('-') + break + case 'dd-mm-yy': + [day, month, year] = input.value.split('-') + break + case 'yy/mm/dd': + [year, month, day] = input.value.split('/') + break + case 'dd/mm/yy': + [day, month, year] = input.value.split('/') + break + default: + throw new Error('Future dates are not allowed, but the chosen date could not be parsed') + } + const chosenDate = Date.parse(`${year}-${month}-${day}T00:00:00.000`) + const today = new Date() + const thisMonth = today.getMonth() < 9 ? `0${today.getMonth() + 1}` : today.getMonth() + 1 + const formatToday = Date.parse( + `${today.getFullYear()}-${thisMonth}-${today.getDate()}T00:00:00.000` + ) + return chosenDate < (formatToday + 86400000) + } return true; } } diff --git a/includes/lib/msf-blocks/date/msf-block-date.class.php b/includes/lib/msf-blocks/date/msf-block-date.class.php index 65c3d2f..27a6fa6 100644 --- a/includes/lib/msf-blocks/date/msf-block-date.class.php +++ b/includes/lib/msf-blocks/date/msf-block-date.class.php @@ -36,7 +36,7 @@ public function __construct ($label, $required, $format, $allowfuturedates = tru public function render($ids) { $locale = substr(get_locale(), 0, 2) === 'de' ? 'de' : 'en'; // TODO this is possibly not a good idea ?> -
+
From 2afdfff7ca4dcb507d032f1e365b605e29600489 Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Wed, 31 Jan 2024 09:33:40 +0100 Subject: [PATCH 5/9] Add translation for future dates restriction --- lang/multi-step-form.pot | 84 +++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/lang/multi-step-form.pot b/lang/multi-step-form.pot index 5ae0540..7846fe8 100644 --- a/lang/multi-step-form.pot +++ b/lang/multi-step-form.pot @@ -150,162 +150,166 @@ msgid "Date Format" msgstr "" #: includes/admin/msf-admin.class.php:89 +msgid "Allow future dates" +msgstr "" + +#: includes/admin/msf-admin.class.php:90 msgid "Required" msgstr "" -#: includes/admin/msf-admin.class.php:91 +#: includes/admin/msf-admin.class.php:92 msgid "Header" msgstr "" -#: includes/admin/msf-admin.class.php:92 +#: includes/admin/msf-admin.class.php:93 msgid "Option" msgstr "" -#: includes/admin/msf-admin.class.php:93 +#: includes/admin/msf-admin.class.php:94 msgid "Options" msgstr "" -#: includes/admin/msf-admin.class.php:94 +#: includes/admin/msf-admin.class.php:95 msgid "Add option" msgstr "" -#: includes/admin/msf-admin.class.php:95 +#: includes/admin/msf-admin.class.php:96 msgid "Multiple Selection" msgstr "" -#: includes/admin/msf-admin.class.php:98 +#: includes/admin/msf-admin.class.php:99 msgid "Options (one per line)" msgstr "" -#: includes/admin/msf-admin.class.php:99 +#: includes/admin/msf-admin.class.php:100 msgid "Enable search" msgstr "" -#: includes/admin/msf-admin.class.php:100 +#: includes/admin/msf-admin.class.php:101 msgid "Set placeholder" msgstr "" -#: includes/admin/msf-admin.class.php:103 +#: includes/admin/msf-admin.class.php:104 msgid "Text" msgstr "" -#: includes/admin/msf-admin.class.php:104 +#: includes/admin/msf-admin.class.php:105 msgid "Paragraph text" msgstr "" -#: includes/admin/msf-admin.class.php:107, includes/lib/msf-blocks/media/msf-block-media.class.php:59 +#: includes/admin/msf-admin.class.php:108, includes/lib/msf-blocks/media/msf-block-media.class.php:59 msgid "Media" msgstr "" -#: includes/admin/msf-admin.class.php:108 +#: includes/admin/msf-admin.class.php:109 msgid "Select Media" msgstr "" -#: includes/admin/msf-admin.class.php:109 +#: includes/admin/msf-admin.class.php:110 msgid "Place an image or video in your form." msgstr "" -#: includes/admin/msf-admin.class.php:110 +#: includes/admin/msf-admin.class.php:111 msgid "Select a media element" msgstr "" -#: includes/admin/msf-admin.class.php:111 +#: includes/admin/msf-admin.class.php:112 msgid "Title" msgstr "" -#: includes/admin/msf-admin.class.php:112 +#: includes/admin/msf-admin.class.php:113 msgid "Filename" msgstr "" -#: includes/admin/msf-admin.class.php:113 +#: includes/admin/msf-admin.class.php:114 msgid "Preview" msgstr "" -#: includes/admin/msf-admin.class.php:116 +#: includes/admin/msf-admin.class.php:117 msgid "GET Parameter" msgstr "" -#: includes/admin/msf-admin.class.php:119 +#: includes/admin/msf-admin.class.php:120 msgid "Minimum" msgstr "" -#: includes/admin/msf-admin.class.php:120 +#: includes/admin/msf-admin.class.php:121 msgid "Maximum" msgstr "" -#: includes/admin/msf-admin.class.php:121 +#: includes/admin/msf-admin.class.php:122 msgid "No Minimum" msgstr "" -#: includes/admin/msf-admin.class.php:122 +#: includes/admin/msf-admin.class.php:123 msgid "No Maximum" msgstr "" -#: includes/admin/msf-admin.class.php:125 +#: includes/admin/msf-admin.class.php:126 msgid "Confirm" msgstr "" -#: includes/admin/msf-admin.class.php:127 +#: includes/admin/msf-admin.class.php:128 msgid "RegEx Filter" msgstr "" -#: includes/admin/msf-admin.class.php:128 +#: includes/admin/msf-admin.class.php:129 msgid "Custom RegEx Error Message" msgstr "" -#: includes/admin/msf-admin.class.php:130 +#: includes/admin/msf-admin.class.php:131 msgid "Please select the registration fields to be displayed to the user. Email is always required. If the user does not specify a username or password, WordPress is auto-generating these and sending them to the user via email." msgstr "" -#: includes/admin/msf-admin.class.php:131 +#: includes/admin/msf-admin.class.php:132 msgid "You are already registered and logged in." msgstr "" -#: includes/admin/msf-admin.class.php:132 +#: includes/admin/msf-admin.class.php:133 msgid "Username" msgstr "" -#: includes/admin/msf-admin.class.php:133, includes/lib/msf-blocks/email/msf-block-email.class.php:69, includes/msf-settings.class.php:48 +#: includes/admin/msf-admin.class.php:134, includes/lib/msf-blocks/email/msf-block-email.class.php:69, includes/msf-settings.class.php:48 msgid "Email" msgstr "" -#: includes/admin/msf-admin.class.php:134 +#: includes/admin/msf-admin.class.php:135 msgid "Password" msgstr "" -#: includes/admin/msf-admin.class.php:135 +#: includes/admin/msf-admin.class.php:136 msgid "Confirm Password" msgstr "" -#: includes/admin/msf-admin.class.php:136 +#: includes/admin/msf-admin.class.php:137 msgid "First Name" msgstr "" -#: includes/admin/msf-admin.class.php:137 +#: includes/admin/msf-admin.class.php:138 msgid "Last Name" msgstr "" -#: includes/admin/msf-admin.class.php:138 +#: includes/admin/msf-admin.class.php:139 msgid "Website" msgstr "" -#: includes/admin/msf-admin.class.php:139 +#: includes/admin/msf-admin.class.php:140 msgid "Biographical Info" msgstr "" -#: includes/admin/msf-admin.class.php:188 +#: includes/admin/msf-admin.class.php:189 msgid "Not installed/active" msgstr "" -#: includes/admin/msf-admin.class.php:287 +#: includes/admin/msf-admin.class.php:288 msgid "Invalid JSON-File. Check your syntax." msgstr "" -#: includes/admin/msf-admin.class.php:315 +#: includes/admin/msf-admin.class.php:316 msgid "Forms must be imported as JSON files" msgstr "" -#: includes/admin/msf-admin.class.php:420, includes/admin/partials/msf-editor.php:8 +#: includes/admin/msf-admin.class.php:421, includes/admin/partials/msf-editor.php:8 msgid "Success. Form saved." msgstr "" @@ -561,7 +565,7 @@ msgstr "" msgid "Please send us a screenshot of the following information, if you write us because of a technical problem." msgstr "" -#: includes/lib/msf-blocks/date/msf-block-date.class.php:68 +#: includes/lib/msf-blocks/date/msf-block-date.class.php:72 msgid "Date" msgstr "" From 94f554157d7e84582c16d3225c75481e11728aa0 Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Fri, 2 Feb 2024 10:07:13 +0100 Subject: [PATCH 6/9] Make sure date validation takes days below 10 into account when parsing --- assets/js/frontend/frontend.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/frontend/frontend.ts b/assets/js/frontend/frontend.ts index c711d3e..e49bd05 100644 --- a/assets/js/frontend/frontend.ts +++ b/assets/js/frontend/frontend.ts @@ -653,8 +653,9 @@ jQuery(document).ready(function ($) { const chosenDate = Date.parse(`${year}-${month}-${day}T00:00:00.000`) const today = new Date() const thisMonth = today.getMonth() < 9 ? `0${today.getMonth() + 1}` : today.getMonth() + 1 + const thisDate = today.getDate() < 10 ? `0${today.getDate()}` : today.getDate() const formatToday = Date.parse( - `${today.getFullYear()}-${thisMonth}-${today.getDate()}T00:00:00.000` + `${today.getFullYear()}-${thisMonth}-${thisDate}T00:00:00.000` ) return chosenDate < (formatToday + 86400000) } From cf7e42eee50b6465da43840b8cd1269af51ca25d Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Fri, 2 Feb 2024 10:22:39 +0100 Subject: [PATCH 7/9] Warn user when future date is chosen when it is not allowed --- assets/js/frontend/frontend.ts | 3 +++ includes/msf.class.php | 1 + lang/multi-step-form.pot | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/assets/js/frontend/frontend.ts b/assets/js/frontend/frontend.ts index e49bd05..c3150eb 100644 --- a/assets/js/frontend/frontend.ts +++ b/assets/js/frontend/frontend.ts @@ -657,6 +657,9 @@ jQuery(document).ready(function ($) { const formatToday = Date.parse( `${today.getFullYear()}-${thisMonth}-${thisDate}T00:00:00.000` ) + if (chosenDate >= (formatToday + 86400000)) { + alert(msfAjax.i18n.errors.noFutureDates) + } return chosenDate < (formatToday + 86400000) } return true; diff --git a/includes/msf.class.php b/includes/msf.class.php index 0689932..3dc500a 100755 --- a/includes/msf.class.php +++ b/includes/msf.class.php @@ -170,6 +170,7 @@ public static function get_translation() { 'invalidRegex' => __('Invalid input', 'multi-step-form'), 'noCaptcha' => __('Please solve the captcha first!', 'multi-step-form'), 'emailsDontMatch' => __('Emails provided don\'t match!', 'multi-step-form'), + 'noFutureDates' => __('No future dates allowed', 'multi-step-form'), ), ); } diff --git a/lang/multi-step-form.pot b/lang/multi-step-form.pot index 7846fe8..f4cb96c 100644 --- a/lang/multi-step-form.pot +++ b/lang/multi-step-form.pot @@ -928,3 +928,7 @@ msgstr "" #: includes/msf.class.php:172 msgid "Emails provided don't match!" msgstr "" + +#: includes/msf.class.php:173 +msgid "No future dates allowed" +msgstr "" From 1d957dfd9d09504d17509228e55914c509aa820b Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Fri, 2 Feb 2024 13:31:02 +0100 Subject: [PATCH 8/9] Take user-input that leaves out preceding zeroes into account --- assets/js/frontend/frontend.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/js/frontend/frontend.ts b/assets/js/frontend/frontend.ts index c3150eb..34acd00 100644 --- a/assets/js/frontend/frontend.ts +++ b/assets/js/frontend/frontend.ts @@ -650,6 +650,8 @@ jQuery(document).ready(function ($) { default: throw new Error('Future dates are not allowed, but the chosen date could not be parsed') } + day = Number(day) < 10 ? `0${Number(day)}` : Number(day) + month = Number(month) < 10 ? `0${Number(month)}` : Number(month) const chosenDate = Date.parse(`${year}-${month}-${day}T00:00:00.000`) const today = new Date() const thisMonth = today.getMonth() < 9 ? `0${today.getMonth() + 1}` : today.getMonth() + 1 From c2a8cdb852bf790a9585af114c7a3c7fcf563528 Mon Sep 17 00:00:00 2001 From: Luke1982 Date: Tue, 6 Feb 2024 15:46:31 +0100 Subject: [PATCH 9/9] Remove leftover testing dump --- includes/lib/msf-wizard-service.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/lib/msf-wizard-service.class.php b/includes/lib/msf-wizard-service.class.php index 49cf053..3397e2e 100755 --- a/includes/lib/msf-wizard-service.class.php +++ b/includes/lib/msf-wizard-service.class.php @@ -22,7 +22,6 @@ public function get_by_id($id) { $row = $this->_repository->find_by_id($id); if ($row) { - file_put_contents('test.txt', var_export(Mondula_Form_Wizard_Wizard::from_aa(json_decode($row->json, true), $this->_plugin_version, $row->version), true)); return Mondula_Form_Wizard_Wizard::from_aa(json_decode($row->json, true), $this->_plugin_version, $row->version); } else { return null;