[英]symfony2 form disable
我使用相同的表單來“預覽”對象,因為我要“編輯/更新”同一個對象。 在我的控制器的showAction()
中,我有以下代碼:
$form = $this->createForm(new SalesEntityType($entity), $entity, array('read_only' => true) );
此代碼適用於主要表單,但有許多子表單通過包含成為其中的一部分。 show.html.twig中的一個例子是:
{% include 'TargetCommonBundle:Hours:hoursForm.html.twig' with { form: hours } %}
不幸的是,父表單上的read_only設置似乎沒有級聯到包含的子表單。 有辦法處理這個嗎?
嘗試:
$form = $this->createForm( new SalesEntityType($entity), $entity, [ 'disabled' => true ] );
請參閱:vendor / symfony / symfony / src / Symfony / Component / Form / CHANGELOG.md,第一行
// It is the way more fast to disabled a form
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->setDisabled(true);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.