Symfony 将字段值复制到另一个字段
我想隐藏Symfony 将字段值复制到另一个字段,symfony,twig,Symfony,Twig,我想隐藏form.title字段,并将form.title字段值设置为form.oro\u eventname 用户只能查看form.oro\u eventname,但form.oro\u eventname的值会复制到form.title 有人能告诉我怎么做吗 {% set dataBlocks = [{ 'title': 'General Information'|trans, 'class': 'active', 'subblocks': [ {
form.title
字段,并将form.title
字段值设置为form.oro\u eventname
用户只能查看
form.oro\u eventname
,但form.oro\u eventname
的值会复制到form.title
有人能告诉我怎么做吗
{% set dataBlocks = [{
'title': 'General Information'|trans,
'class': 'active',
'subblocks': [
{
'title': '',
'data': [
form_row(form.title),
form_row(form.oro_eventname),
form_row(form.description),
form_row(form.backgroundColor),
form.calendarUid is defined ? form_row(form.calendarUid) : null,
form_row(form.attendees),
entity.recurrence is null ? form_row(form.reminders) : null,
form_row(form.notifyAttendees),
invitations.notify_attendees_component()
]
},
{
'title': '',
'data': [
'<div ' ~ UI.renderPageComponentAttributes(calendarEventDateRange) ~ '>' ~
form_row(form.start) ~
form_row(form.end) ~
form_row(form.allDay) ~
'</div>',
form.recurrence is defined ? form_row(form.recurrence) : null
]
}
]
}] %}
{%set数据块=[{
“标题”:一般信息,
“类”:“活动”,
“子块”:[
{
“标题”:“,
“数据”:[
表格行(表格标题),
表格行(表格oro事件名称),
表格行(表格说明),
表格行(表格背景色),
是否定义了form.calendarUid?form_行(form.calendarUid):null,
表格行(表格与会者),
entity.recurrence为空?表单行(表单提醒):空,
表格行(表格通知与会者),
邀请。通知与会者\u组件()
]
},
{
“标题”:“,
“数据”:[
'' ~
表格行(表格开始)~
表格行(表格结束)~
表格行(表格全天)~
'',
定义了form.recurrence?form_行(form.recurrence):null
]
}
]
}] %}
您可以使用javascript(例如,一个在keyup事件中触发的函数)实现这一点
或者在你的控制器里
$title = $form->get('oro_eventname')->getData();
$yourEntity -> setTitle($title);
在实体中将标题字段设置为nullable true,这样,若不在表单中添加标题字段,它将不会通过null值的验证错误
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=30, nullable=true)
*/
private $title;
在“添加/编辑”操作中,如果表单像这样有效,请设置标题值
if ($form->isValid()) {
$event = $form->getData();
$event->setTitle($event->getOroEventname());
// Other code like persist flush redirect...
}
我建议使用第二种方法来避免依赖前端代码。有些人使用禁用Javascript来避免在某些设备上做广告。@MartinFasani我同意你的问题并不清楚你想做什么。你能提供更多的细节或者你需要的图片吗?
if ($form->isValid()) {
$event = $form->getData();
$event->setTitle($event->getOroEventname());
// Other code like persist flush redirect...
}