简体   繁体   English

Laravel-在编辑模式下设置复选框/单选

[英]Laravel - set checkbox / radio selected in edit mode

In Laravel, we can set the value for a form field element with this: 在Laravel中,我们可以这样设置表单字段元素的值:

{{Form::text('name', 'predefined name')}}

The above work well, even in the edit mode the predefined name will always appear in the text field. 上面的方法效果很好,即使在编辑模式下, predefined name也始终会出现在文本字段中。 However, for checkbox and radio button, it does not work. 但是,对于复选框和单选按钮,它不起作用。

{{Form::checkbox('country', 'UK',true)}}
{{Form::radio('gender', 'male',true)}}
{{Form::radio('gender', 'female',false)}}

No matter what I set for the checkbox & radio button, it will be ignored and use the data from database. 无论我为复选框和单选按钮设置了什么,它将被忽略并使用数据库中的数据。 This become an huge trouble for array of checkbox. 这对于复选框数组来说是一个巨大的麻烦。

{{Form::checkbox('country[]', 'UK',true)}}
{{Form::checkbox('country[]', 'SG',false)}}
{{Form::checkbox('country[]', 'US',false)}}

How can I solve it? 我该如何解决? Thank you. 谢谢。

如果您指的是复选框或单选框的值的可见性:通常,您会通过标签将文本添加到复选框或单选框。

{{ Label::for('nameOfInput', 'Value') }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM