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/assets/js/frontend/frontend.ts b/assets/js/frontend/frontend.ts index abcb74a..34acd00 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; } @@ -629,6 +629,41 @@ 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') + } + 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 + const thisDate = today.getDate() < 10 ? `0${today.getDate()}` : today.getDate() + 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/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'), 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..27a6fa6 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,12 +30,13 @@ public function __construct ($label, $required, $format) { } else { $this->_format = 'yy-mm-dd'; } + $this->_allowfuturedates = $allowfuturedates; } public function render($ids) { $locale = substr(get_locale(), 0, 2) === 'de' ? 'de' : 'en'; // TODO this is possibly not a good idea ?> -
+
@@ -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-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); } } 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 5ae0540..f4cb96c 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 "" @@ -924,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 ""