fixed rendering of date block + fixed validation for dates
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
abstract class Base {
|
||||
protected static function getInputValidation($block) {
|
||||
protected static function getInputValidation($block, $extra_rules = array()) {
|
||||
$rules = array();
|
||||
|
||||
if($block['id'] === 'email') {
|
||||
@@ -37,8 +37,15 @@ abstract class Base {
|
||||
$rules['required-message'] = __('Please select at least one option');
|
||||
}
|
||||
|
||||
if($block['type'] === 'date') {
|
||||
$rules['group'] = 'custom_field_'.$block['id'];
|
||||
$rules['errors-container'] = '.mailpoet_error_'.$block['id'];
|
||||
}
|
||||
|
||||
$validation = array();
|
||||
|
||||
$rules = array_merge($rules, $extra_rules);
|
||||
|
||||
if(!empty($rules)) {
|
||||
$rules = array_unique($rules);
|
||||
foreach($rules as $rule => $value) {
|
||||
|
@@ -19,7 +19,6 @@ class Date extends Base {
|
||||
$html = '';
|
||||
|
||||
$field_name = static::getFieldName($block);
|
||||
$field_validation = static::getInputValidation($block);
|
||||
|
||||
$date_formats = static::getDateFormats();
|
||||
|
||||
@@ -70,24 +69,35 @@ class Date extends Base {
|
||||
if($date_selector === 'DD') {
|
||||
$block['selected'] = $day;
|
||||
$html .= '<select class="mailpoet_date_day" ';
|
||||
$html .= static::getInputValidation($block, array(
|
||||
'required-message' => __('Please select a day')
|
||||
));
|
||||
$html .= 'name="'.$field_name.'[day]" placeholder="'.__('Day').'">';
|
||||
$html .= static::getDays($block);
|
||||
$html .= '</select>';
|
||||
} else if($date_selector === 'MM') {
|
||||
$block['selected'] = $month;
|
||||
$html .= '<select class="mailpoet_date_month" ';
|
||||
$html .= static::getInputValidation($block, array(
|
||||
'required-message' => __('Please select a month')
|
||||
));
|
||||
$html .= 'name="'.$field_name.'[month]" placeholder="'.__('Month').'">';
|
||||
$html .= static::getMonths($block);
|
||||
$html .= '</select>';
|
||||
} else if($date_selector === 'YYYY') {
|
||||
$block['selected'] = $year;
|
||||
$html .= '<select class="mailpoet_date_year" ';
|
||||
$html .= static::getInputValidation($block, array(
|
||||
'required-message' => __('Please select a year')
|
||||
));
|
||||
$html .= 'name="'.$field_name.'[year]" placeholder="'.__('Year').'">';
|
||||
$html .= static::getYears($block);
|
||||
$html .= '</select>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '<span class="mailpoet_error_'.$block['id'].'"></span>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
@@ -9,17 +9,17 @@
|
||||
{{> _settings_date_days }}
|
||||
{{> _settings_date_years }}
|
||||
{{/unless}}
|
||||
{{#ifCond params.date_format "==" "mm/dd/yyyy"}}
|
||||
{{#ifCond params.date_format "==" "MM/DD/YYYY"}}
|
||||
{{> _settings_date_months }}
|
||||
{{> _settings_date_days }}
|
||||
{{> _settings_date_years }}
|
||||
{{/ifCond}}
|
||||
{{#ifCond params.date_format "==" "dd/mm/yyyy"}}
|
||||
{{#ifCond params.date_format "==" "DD/MM/YYYY"}}
|
||||
{{> _settings_date_days }}
|
||||
{{> _settings_date_months }}
|
||||
{{> _settings_date_years }}
|
||||
{{/ifCond}}
|
||||
{{#ifCond params.date_format "==" "yyyy/mm/dd"}}
|
||||
{{#ifCond params.date_format "==" "YYYY/MM/DD"}}
|
||||
{{> _settings_date_years }}
|
||||
{{> _settings_date_months }}
|
||||
{{> _settings_date_days }}
|
||||
@@ -31,11 +31,11 @@
|
||||
{{> _settings_date_months }}
|
||||
{{> _settings_date_years }}
|
||||
{{/unless}}
|
||||
{{#ifCond params.date_format "==" "mm/yyyy"}}
|
||||
{{#ifCond params.date_format "==" "MM/YYYY"}}
|
||||
{{> _settings_date_months }}
|
||||
{{> _settings_date_years }}
|
||||
{{/ifCond}}
|
||||
{{#ifCond params.date_format "==" "yyyy/mm"}}
|
||||
{{#ifCond params.date_format "==" "YYYY/MM"}}
|
||||
{{> _settings_date_years }}
|
||||
{{> _settings_date_months }}
|
||||
{{/ifCond}}
|
||||
|
Reference in New Issue
Block a user