Laravel刀片复选框 [英] Laravel blade check box

查看:72
本文介绍了Laravel刀片复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据库设置复选框状态,所以我写,

I want to set check-boxes state from database, so I write,

{{ Form::checkbox('asap', null, $offer->asap) }}

但是如果我想将'id'设置为复选框

But if I want to set 'id' to the check-box like

{{ Form::checkbox('asap', null, $offer->ASAP, array('id'=>'asap')) }}

它总是将我的复选框状态设置为true. (在用户选择之前)

It always set my check-box state to true. (Before user select it)

那么,如果在用户选择复选框状态之前设置了复选框状态,那么该如何在刀片服务器复选框中设置"id"呢?

So question how set 'id' in blade check-boxes when check-box state is set before user select it?

推荐答案

第3个参数决定是否选中复选框.因此,$offer->ASAP(或$offer->asap为true(或非false或非null).如果要取消选中复选框,则将其设置为false,或不使用第3个参数(设置为null或false). :

3rd argument decides whether checkbox is checked or not. So probably $offer->ASAP (or $offer->asap is true (or not false or not null). If you want to to make checkbox unchecked either set it to false, or don't use 3rd argument (set to to null or false):

{{ Form::checkbox('asap',null,null, array('id'=>'asap')) }}

编辑

另一种可能性是您的页面上有一些自定义JavaScript代码,这些代码通过asap id查找元素并选中此复选框.因此,当您未设置ID时,JavaScript将无法对其进行检查,但是当您设置此ID时,JavaScript将选中该复选框.

Another possibility is that you have on your page some custom JavaScript code that finds element by asap id and checks this checkbox. So when you don't set id, JavaScript cannot check it, but when you set this id, the checkbox will be checked by JavaScript.

这篇关于Laravel刀片复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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