update:更新form功能
This commit is contained in:
parent
114387d030
commit
2f25a0892e
@ -22,6 +22,20 @@ class CatchAdmin
|
|||||||
return app()->getRootPath() . self::$root . DIRECTORY_SEPARATOR;
|
return app()->getRootPath() . self::$root . DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 root
|
||||||
|
*
|
||||||
|
* @time 2021年03月28日
|
||||||
|
* @param $root
|
||||||
|
* @return CatchAdmin
|
||||||
|
*/
|
||||||
|
public static function setRoot($root): CatchAdmin
|
||||||
|
{
|
||||||
|
self::$root = $root;
|
||||||
|
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建目录
|
* 创建目录
|
||||||
*
|
*
|
||||||
|
@ -58,7 +58,6 @@ abstract class Form
|
|||||||
use UploadFactoryTrait;
|
use UploadFactoryTrait;
|
||||||
use ValidateFactoryTrait;
|
use ValidateFactoryTrait;
|
||||||
use GroupFactoryTrait;
|
use GroupFactoryTrait;
|
||||||
use FormOptions;
|
|
||||||
use FormValidates;
|
use FormValidates;
|
||||||
|
|
||||||
protected $primaryKeyField = 'id';
|
protected $primaryKeyField = 'id';
|
||||||
@ -121,9 +120,13 @@ abstract class Form
|
|||||||
*/
|
*/
|
||||||
protected function getFields(): array
|
protected function getFields(): array
|
||||||
{
|
{
|
||||||
return array_merge($this->fields(), [
|
if ($this->primaryKeyField) {
|
||||||
self::hidden($this->primaryKeyField, 0)
|
return array_merge($this->fields(), [
|
||||||
]);
|
self::hidden($this->primaryKeyField, 0)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fields();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,10 +138,6 @@ abstract class Form
|
|||||||
*/
|
*/
|
||||||
public function rule(array $rules): array
|
public function rule(array $rules): array
|
||||||
{
|
{
|
||||||
if ($this->primaryKeyField) {
|
|
||||||
array_push($rules, self::hidden($this->primaryKeyField, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
return Elm::createForm('', $rules)->formRule();
|
return Elm::createForm('', $rules)->formRule();
|
||||||
} catch (FormBuilderException $e) {
|
} catch (FormBuilderException $e) {
|
||||||
@ -251,4 +250,15 @@ abstract class Form
|
|||||||
->data(['none' => ''])
|
->data(['none' => ''])
|
||||||
->headers(self::authorization());
|
->headers(self::authorization());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* options
|
||||||
|
*
|
||||||
|
* @time 2021年03月24日
|
||||||
|
* @return FormOptions
|
||||||
|
*/
|
||||||
|
public static function options(): FormOptions
|
||||||
|
{
|
||||||
|
return new FormOptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,29 +14,36 @@
|
|||||||
namespace catcher\library\form;
|
namespace catcher\library\form;
|
||||||
|
|
||||||
|
|
||||||
trait FormOptions
|
class FormOptions
|
||||||
{
|
{
|
||||||
|
protected $options = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是/否的选项
|
* 增加 option
|
||||||
*
|
*
|
||||||
* @time 2021年03月06日
|
* @time 2021年03月24日
|
||||||
* @param array $label
|
* @param $label
|
||||||
* @param array $value
|
* @param $value
|
||||||
* @return array[]
|
* @return $this
|
||||||
*/
|
*/
|
||||||
protected function yesOrNo(array $label = [], array $value = []): array
|
public function add($label, $value): FormOptions
|
||||||
{
|
{
|
||||||
if (!count($label)) {
|
$this->options[] = [
|
||||||
$label = ['是', '否'];
|
'value' => $value,
|
||||||
}
|
'label' => $label,
|
||||||
|
|
||||||
if (!count($value)) {
|
|
||||||
$value = [1, 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
['value' => $value[0], 'label' => $label[0]],
|
|
||||||
['value' => $value[1], 'label' => $label[1]],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取
|
||||||
|
*
|
||||||
|
* @time 2021年03月24日
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return $this->options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,18 @@ namespace catcher\library\form;
|
|||||||
|
|
||||||
trait FormValidates
|
trait FormValidates
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 正则验证
|
||||||
|
*
|
||||||
|
* @time 2021年03月06日
|
||||||
|
* @param string $pattern
|
||||||
|
* @return \FormBuilder\UI\Elm\Validate
|
||||||
|
*/
|
||||||
|
public static function validatePattern(string $pattern): \FormBuilder\UI\Elm\Validate
|
||||||
|
{
|
||||||
|
return self::validateStr()->pattern($pattern);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 纯数字验证
|
* 纯数字验证
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user