简体   繁体   中英

Octobercms disble fields in relation

I want to disable form fields in the update context, see the image:

关联领域

I tried this, but it did not work

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

Seems you are trying to make relation manager field disable(read only)

But I am sure they are not following same patter as normal widgets do .

they can not be disabled directly like that as I found other easy way .

you may have used partial for rendering this relational field ( book | user ) and your partial _books.htm is looking like this.

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

You need to change it with this one

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

The magic config value is this readOnly property it will make list read-only or active working .

try this it will work , if not please comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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