【问题标题】:OctoberCMS Builder Relation Checkboxes Default ValueOctoberCMS Builder 关系复选框默认值
【发布时间】:2018-03-31 18:23:22
【问题描述】:

我有一个多对多关系,由后端表单中的复选框表示。创建新记录时如何设置表单以选中所有复选框?

【问题讨论】:

    标签: octobercms octobercms-builder


    【解决方案1】:

    hmm 不确定我们能否以正确的方式做到这一点,因为实际上要选中该复选框,我们需要 DB 中的实际关系,但当时我们没有这样的关系,但我们可以为此做一些修改

    好的,首先如果您使用表单生成器创建表单,you have controller and its view files

    现在转到它的视图文件找到create.htm 现在找到这一行<?php Block::endPut() ?> 和粘贴 this code after。 像这样

    <?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>
    

    这些代码在页面加载时会选中所有的复选框。

    这不是最好的方法,有点像 hack,因为我没有找到任何好的简单替代方法。

    如果您发现任何困难,请发表评论。

    【讨论】:

      猜你喜欢
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多