【发布时间】:2017-09-13 06:10:14
【问题描述】:
我正在使用OctoberCMS,并且我已经使用Builder 插件创建了我的一个名为Properties 的插件,到目前为止效果很好。
问题是,我有两个字段,分别称为 authority 和 auction_date。
authority 是一个下拉字段,其中包含 auction 等选项。而auction_date 是一个简单的date 字段。
auction_date 字段依赖于authority 字段,并且仅当authority 字段具有称为auction 的选定值且authority 字段不是同时需要时才需要。因此,我将以下代码放在我的属性插件的模型文件中。
模型文件 - Property.php
public $rules = [
'auction_date' => 'required_if:authority,==,auction',
];
这很好用,如果authority 下拉列表的值从列表中选择auction,我可以验证我的auction_date 字段。
但是,这里基本上auction_date 默认不是必填字段。是authority的依赖字段。
当我加载页面时,该字段旁边显示 asterisk(*) 的字段。下面是它的样子。
我已尝试更新我的插件的 fields.yaml 文件,并将其放在下面的代码中。
auction_date:
label: 'Auction Date:'
oc.commentPosition: ''
mode: date
span: auto
type: datepicker
tab: 'Address Information'
required: false
此代码required: false 对我不起作用。
我遇到了更新以下系统库文件的解决方案。
- 模块/后端/类/FormField.php
- modules/backend/widgets/Form.php
这样做,Field definition should override magic。
但坦率地说,我不想在这里弄乱任何系统文件。如果我能找到一些可以在一个插件文件中处理这个问题的解决方案,那将是理想的。
如果有人指导我完成这件事,那就太棒了。
提前致谢。
【问题讨论】:
标签: php octobercms octobercms-plugins octobercms-backend october-form-controller