简体   繁体   English

OctoberCMS构建器关系复选框默认值

[英]OctoberCMS Builder Relation Checkboxes Default Value

I have a many-to-many relationship which is represented by checkbox in the back-end forms. 我有一个多对多关系,由后端表单中的复选框表示。 How could I set the form up to have all the checkbox checked when creating a new record? 创建新记录时,如何设置表格以选中所有复选框?

hmm not sure we can do it in correct way because actually to make that check box selected we need actual relation in DB but at that moment we don't have that so, but we can make some hack for it 嗯,不确定我们是否可以以正确的方式进行操作,因为实际上要选中此复选框,我们需要在数据库中建立实际的关系,但是那时我们还没有这样做,但是我们可以为此做些修改

ok, so first if you created form using form builder, you have controller and its view files 好的,所以首先,如果您使用表单构建器创建了表单,则you have controller and its view files

now go to its view files find create.htm now find this line <?php Block::endPut() ?> and paste this code after . 现在转到其视图文件,找到create.htm现在找到这一行<?php Block::endPut() ?> 并将 this code after 粘贴 this code after like this 像这样

<?php Block::endPut() ?>

/* just replace User[groups][] with your field name */
/* here User => your model name first latter caps */
/* [groups] => your relation name all small */
/* or you can inspect it and paste it here using devtools */
<script>
    jQuery(document).ready(function(){
        jQuery("[name='User[groups][]']").attr('checked', true)
        /* replace here ^ */
    })
</script>

these peace of code will check all the box when page loads. 这些安全的代码将在页面加载时选中所有复选框。

its not the best way, kind of hack, as I didn't find any good easy alternative so. 这不是最好的方法,是一种hack,因为我没有找到任何简便的替代方法。

please comment if you find any difficulties. 如果发现任何困难,请发表评论。

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

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