繁体   English   中英

Octobercms消除了相关领域

[英]Octobercms disble fields in relation

我想在更新上下文中禁用表单字段,请参见图片:

关联领域

我试过了,但是没用

public function filterFields($fields, $context = null)
{
    if($context == 'update') {
        $fields->books->disabled = true;
        $fields->user->disabled = true;
    }
}

似乎您正在尝试禁用 relation manager field (只读)

但是我相信他们不会 same patter as normal widgets do遵循same patter as normal widgets do

他们不能像我发现的其他简便方法那样直接禁用。

您可能已经使用了partial for rendering this relational field (book | user),而您的_books.htm部分看起来像这样。

<?= $this->relationRender('comments', ['readOnly' => false]) ?>

你需要用这个改变

<?php if($this->widget->form->context == 'update'): ?>
    <?= $this->relationRender('comments', ['readOnly' => true]) ?>
<?php else: ?>
    <?= $this->relationRender('comments', ['readOnly' => false]) ?>
<?php endif; ?>

神奇的config值是这个readOnly属性,它将使列表为read-only or active working

尝试此操作将起作用,否则请发表评论。

暂无
暂无

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

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