问题描述
上下文
我实际上是在尝试更改 OroDateTimeType::class
的时间输入的默认占位符。
例如,我想要文本 Horaires
而不是 Temps
。
这是我的 FormType 中的表单字段:
->add('expirationDate',OroDateTimeType::class,[
'label' => 'app.subscription.fields.expirationDate',])
在我的树枝视图中:
form_row(form.expirationDate)
问题
一开始,我尝试将 Symfony 4 placeholder
选项用于 DateTime 类型:https://symfony.com/doc/4.4/reference/forms/types/date.html#placeholder。它不起作用,因为 OroDateTime
使用不同的日期选择器并且它在加载时覆盖 Symfony 值:
{# vendor/oro/platform/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig #}
{% block oro_datetime_widget %}
{% set dateValidation = {'Date' : {}} %}
{% set timeValidation = {'Time' : {}} %}
{% if required %}
{% set dateValidation = dateValidation|merge({'NotBlank' : {}}) %}
{% set timeValidation = timeValidation|merge({'NotBlank' : {}}) %}
{% endif %}
{% if attribute(attr,'class') is defined %}
{% set attrClass = attr['class'] %}
{% else %}
{% set attrClass = '' %}
{% endif %}
{% set options = {
view: 'oroui/js/app/views/datepicker/datetimepicker-view',nativeMode: isMobileVersion(),dateInputAttrs: {
placeholder: 'oro.form.choose_date'|trans,id: id,name: id,class: 'input-small datepicker-input ' ~ attrClass,'data-validation': dateValidation|json_encode(constant('JSON_FORCE_OBJECT')),'aria-live': 'assertive',autocomplete: 'off',autocorrect: 'off',autocapitalize: 'off'
},datePickerOptions: {
altFormat: 'yy-mm-dd',changeMonth: true,changeYear: true,yearRange: years|default('-80:+1'),showButtonPanel: true
},timeInputAttrs: {
placeholder: 'oro.form.choose_time'|trans,id: 'time_selector_' ~ id,name: 'time_selector_' ~ id,class: 'input-small timepicker-input ' ~ attrClass,'data-validation': timeValidation|json_encode(constant('JSON_FORCE_OBJECT'))
},timePickerOptions: {
}
} %}
{% set id = 'hidden_' ~ id %}
{% set attr = attr|merge({
'data-page-component-module': 'oroui/js/app/components/view-component','data-page-component-options': options|json_encode(constant('JSON_FORCE_OBJECT'))
}) %}
{{ block('datetime_widget') }}
{% endblock oro_datetime_widget %}
如果我更改 timeInputAttrs.placeholder
变量中的值 options
。有用。
但是,我想将此变量传递给我的特定表单字段,而不是全局。
更新
我最终选择全局更改我项目中的 oro.form.choose_time
翻译。
因此,在我的 Resources/translations/messages.fr_FR.yml
中,我创建了以下几行:
oro:
form:
choose_time: Horaires
auth:
description:
main: Baltimore
然后,我了解到翻译是在位于 var/cache/dev/translations/catalogue.fr_FR
的文件中生成的:
<?php
use Symfony\Component\Translation\MessageCatalogue;
$catalogue = new MessageCatalogue('fr_FR',array (
'messages' =>
array (
'oro.form.choose_time' => 'Temps','oro.auth.description.main' => 'Baltimore',
在这里,我可以看到应用了 oro.auth.description.main
更改,但键 oro.form.choose_time
的值仍然相同。
也许我有一个命令可以运行?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)