update:更新form功能

This commit is contained in:
JaguarJack 2021-03-29 19:51:41 +08:00
parent 114387d030
commit 2f25a0892e
4 changed files with 69 additions and 26 deletions

View File

@ -22,6 +22,20 @@ class CatchAdmin
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();
}
/**
* 创建目录
*

View File

@ -58,7 +58,6 @@ abstract class Form
use UploadFactoryTrait;
use ValidateFactoryTrait;
use GroupFactoryTrait;
use FormOptions;
use FormValidates;
protected $primaryKeyField = 'id';
@ -121,9 +120,13 @@ abstract class Form
*/
protected function getFields(): array
{
return array_merge($this->fields(), [
self::hidden($this->primaryKeyField, 0)
]);
if ($this->primaryKeyField) {
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
{
if ($this->primaryKeyField) {
array_push($rules, self::hidden($this->primaryKeyField, 0));
}
try{
return Elm::createForm('', $rules)->formRule();
} catch (FormBuilderException $e) {
@ -251,4 +250,15 @@ abstract class Form
->data(['none' => ''])
->headers(self::authorization());
}
/**
* options
*
* @time 2021年03月24日
* @return FormOptions
*/
public static function options(): FormOptions
{
return new FormOptions();
}
}

View File

@ -14,29 +14,36 @@
namespace catcher\library\form;
trait FormOptions
class FormOptions
{
protected $options = [];
/**
* /否的选项
* 增加 option
*
* @time 2021年03月06
* @param array $label
* @param array $value
* @return array[]
* @time 2021年03月24
* @param $label
* @param $value
* @return $this
*/
protected function yesOrNo(array $label = [], array $value = []): array
public function add($label, $value): FormOptions
{
if (!count($label)) {
$label = ['是', '否'];
}
if (!count($value)) {
$value = [1, 2];
}
return [
['value' => $value[0], 'label' => $label[0]],
['value' => $value[1], 'label' => $label[1]],
$this->options[] = [
'value' => $value,
'label' => $label,
];
return $this;
}
/**
* 获取
*
* @time 2021年03月24日
* @return array
*/
public function render()
{
return $this->options;
}
}

View File

@ -3,6 +3,18 @@ namespace catcher\library\form;
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);
}
/**
* 纯数字验证
*