Mark up <time> in validation errors

Allow better localisation of values in JS
This commit is contained in:
Ingo Schommer 2017-04-27 21:44:52 +12:00
parent a2ee6a76a0
commit 22f232ed4d
2 changed files with 42 additions and 8 deletions

View File

@ -7,6 +7,7 @@ use SilverStripe\i18n\i18n;
use InvalidArgumentException;
use SilverStripe\ORM\FieldType\DBDate;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationResult;
/**
* Form used for editing a date stirng
@ -403,8 +404,16 @@ class DateField extends TextField
_t(
'DateField.VALIDDATEMINDATE',
"Your date has to be newer or matching the minimum allowed date ({date})",
['date' => $this->internalToFrontend($min)]
)
[
'date' => sprintf(
'<time datetime="%s">%s</time>',
$min,
$this->internalToFrontend($min)
)
]
),
ValidationResult::TYPE_ERROR,
ValidationResult::CAST_HTML
);
return false;
}
@ -420,8 +429,16 @@ class DateField extends TextField
_t(
'DateField.VALIDDATEMAXDATE',
"Your date has to be older or matching the maximum allowed date ({date})",
['date' => $this->internalToFrontend($max)]
)
[
'date' => sprintf(
'<time datetime="%s">%s</time>',
$max,
$this->internalToFrontend($max)
)
]
),
ValidationResult::TYPE_ERROR,
ValidationResult::CAST_HTML
);
return false;
}

View File

@ -6,6 +6,7 @@ use IntlDateFormatter;
use InvalidArgumentException;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationResult;
/**
* Form field used for editing date time strings.
@ -586,8 +587,16 @@ class DatetimeField extends TextField
_t(
'DatetimeField.VALIDDATETIMEMINDATE',
"Your date has to be newer or matching the minimum allowed date and time ({datetime})",
['datetime' => $this->internalToFrontend($min)]
)
[
'datetime' => sprintf(
'<time datetime="%s">%s</time>',
$min,
$this->internalToFrontend($min)
)
]
),
ValidationResult::TYPE_ERROR,
ValidationResult::CAST_HTML
);
return false;
}
@ -603,8 +612,16 @@ class DatetimeField extends TextField
_t(
'DatetimeField.VALIDDATEMAXDATETIME',
"Your date has to be older or matching the maximum allowed date and time ({datetime})",
['datetime' => $this->internalToFrontend($max)]
)
[
'datetime' => sprintf(
'<time datetime="%s">%s</time>',
$max,
$this->internalToFrontend($max)
)
]
),
ValidationResult::TYPE_ERROR,
ValidationResult::CAST_HTML
);
return false;
}