如何呈现一个默认使用symfony2 Form Builder选中的复选框? [英] How to render a checkbox that is checked by default with the symfony2 Form Builder?

查看:62
本文介绍了如何呈现一个默认使用symfony2 Form Builder选中的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有找到简单的方法来简单地选中默认复选框。那可以不那么难,所以我会缺少什么?

I have not found any easy way to accomplish to simply check a Checkbox by default. That can not be that hard, so what am i missing?

推荐答案

您只需将模型或实体中的值设置为true,然后将其传递给FormBuilder,则应进行检查。

You would simply set the value in your model or entity to true and than pass it to the FormBuilder then it should be checked.

如果您看一下文档

创建新任务,然后执行setTask并添加此任务到FormBuilder。如果您对复选框执行相同的操作

A new task is created, then setTask is executed and this task is added to the FormBuilder. If you do the same thing with your checkbox

$object->setCheckboxValue(true);

并传递对象,您应该会看到该复选框处于选中状态。

and pass the object you should see the checkbox checked.

如果它没有按预期工作,请返回一些示例代码以重现该错误。

If it's not working as expected, please get back with some sample code reproducing the error.

这篇关于如何呈现一个默认使用symfony2 Form Builder选中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆