signify-nz / silverstripe-dependentrequiredfields
SilverStripe供应商模块,提供了一种验证器,允许根据其他字段的值使字段成为必填项。
1.1.1
2020-07-23 07:26 UTC
Requires
- athari/yalinqo: ^2.4
- silverstripe/framework: ^4.0
- silverstripe/vendor-plugin: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^3.0
Suggests
- unclecheese/silverstripe-display-logic: Provides the ability to show/hide fields based on the values of other fields.
This package is not auto-updated.
Last update: 2024-09-20 22:37:32 UTC
README
依赖必填字段
依赖必填字段模块提供了一种验证器,它扩展了RequiredFields,并允许根据其他字段的值使字段成为必填项。
SearchFilters用于提供多种比较值的方式,具体取决于什么原因使字段成为必填项。有关如何使用这些内容的更多信息,请参阅SilverStripe的SearchFilters文档。
要求
安装
Composer
composer require signify-nz/silverstripe-dependentrequiredfields
文档
无需配置。以下为示例用法,说明如何使用此验证器。
示例用法
以下示例中,我们有一些字段,它们的必填与否依赖于不同的条件。
AlwaysRequiredField
无论其他字段的值如何,都将必填。
ExactValueField
只有在DependencyField
的值恰好等于someExactValue
时才必填。
StartsWithField
只有在DependencyField
的值以字符串some
开头时才必填。
<?php public function getCMSValidator() { return DependentRequiredFields::create([ 'AlwaysRequiredField', 'ExactValueField' => ['DependencyField' => 'someExactValue'], 'StartsWithField' => ['DependencyField:StartsWith' => 'some'], ]); }
还提供了其他方法来添加或删除依赖必填字段。请注意,上述示例中的AlwaysRequiredField
字段无法使用这些方法添加或删除;应使用RequiredField提供的addRequiredField
和removeRequiredField
字段。
$validator->addDependentRequiredField('GreaterThanField', ['DependencyField:GreaterThan' => '10']); $validator->removeDependentRequiredField('ExactValueField');