mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-01-18 13:28:15 +00:00
form-builder 升级1.2.4
This commit is contained in:
parent
26f3daba97
commit
a6ab8ee153
BIN
vendor/xaboy/form-builder/demo.jpg
vendored
BIN
vendor/xaboy/form-builder/demo.jpg
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB |
185
vendor/xaboy/form-builder/src/components/Validate.php
vendored
Normal file
185
vendor/xaboy/form-builder/src/components/Validate.php
vendored
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FormBuilder表单生成器
|
||||||
|
* Author: xaboy
|
||||||
|
* Github: https://github.com/xaboy/form-builder
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FormBuilder\components;
|
||||||
|
|
||||||
|
use FormBuilder\interfaces\FormComponentInterFace;
|
||||||
|
|
||||||
|
|
||||||
|
class Validate implements FormComponentInterFace
|
||||||
|
{
|
||||||
|
|
||||||
|
const TYPE_STRING = 'string';
|
||||||
|
|
||||||
|
const TYPE_ARRAY = 'array';
|
||||||
|
|
||||||
|
const TYPE_NUMBER = 'number';
|
||||||
|
|
||||||
|
const TYPE_DATE = 'date';
|
||||||
|
|
||||||
|
const TRIGGER_CHANGE = 'change';
|
||||||
|
|
||||||
|
const TRIGGER_BLUR = 'blur';
|
||||||
|
|
||||||
|
protected $validate = [];
|
||||||
|
|
||||||
|
protected $type;
|
||||||
|
|
||||||
|
protected $trigger;
|
||||||
|
|
||||||
|
public function __construct($type, $trigger)
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
$this->trigger = $trigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function str($trigger = self::TRIGGER_CHANGE)
|
||||||
|
{
|
||||||
|
return new static(self::TYPE_STRING,$trigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function arr($trigger = self::TRIGGER_CHANGE)
|
||||||
|
{
|
||||||
|
return new static(self::TYPE_ARRAY,$trigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function num($trigger = self::TRIGGER_CHANGE)
|
||||||
|
{
|
||||||
|
return new static(self::TYPE_NUMBER,$trigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function date($trigger = self::TRIGGER_CHANGE)
|
||||||
|
{
|
||||||
|
return new static(self::TYPE_DATE,$trigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function set($validate, $message = null)
|
||||||
|
{
|
||||||
|
$this->validate[] = $validate + [
|
||||||
|
'trigger' => $this->trigger,
|
||||||
|
'type' => $this->type,
|
||||||
|
'message' => $message
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必须为链接
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function url($message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'type'=>'url'
|
||||||
|
],$message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必须为邮箱
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function email($message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'type'=>'email'
|
||||||
|
],$message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必填
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function required($message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'required' => true,
|
||||||
|
], $message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长度或值必须在这个范围内
|
||||||
|
* @param int $min
|
||||||
|
* @param int $max
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function range($min, $max, $message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'min' => (int)$min,
|
||||||
|
'max' => (int)$max,
|
||||||
|
], $message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长度或值必须大于这个值
|
||||||
|
* @param int $min
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function min($min, $message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'min' => (int)$min,
|
||||||
|
], $message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长度或值必须小于这个值
|
||||||
|
* @param int $max
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function max($max, $message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'max' => (int)$max,
|
||||||
|
], $message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长度或值必须等于这个值
|
||||||
|
* @param int $length
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function length($length, $message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'length' => (int)$length
|
||||||
|
], $message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 值必须在 list 中
|
||||||
|
* @param array $list
|
||||||
|
* @param string|null $message
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function enum($list, $message = null)
|
||||||
|
{
|
||||||
|
$this->set([
|
||||||
|
'type'=>'enum',
|
||||||
|
'enum' => (array)$list
|
||||||
|
], $message);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
return $this->validate;
|
||||||
|
}
|
||||||
|
}
|
||||||
49
vendor/xaboy/form-builder/src/traits/form/FormValidateTrait.php
vendored
Normal file
49
vendor/xaboy/form-builder/src/traits/form/FormValidateTrait.php
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FormBuilder表单生成器
|
||||||
|
* Author: xaboy
|
||||||
|
* Github: https://github.com/xaboy/form-builder
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FormBuilder\traits\form;
|
||||||
|
|
||||||
|
|
||||||
|
use FormBuilder\components\Validate;
|
||||||
|
|
||||||
|
trait FormValidateTrait
|
||||||
|
{
|
||||||
|
public static function validateStr()
|
||||||
|
{
|
||||||
|
return Validate::str();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validateInput()
|
||||||
|
{
|
||||||
|
return Validate::str(Validate::TRIGGER_BLUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validateArr()
|
||||||
|
{
|
||||||
|
return Validate::arr();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validateNum()
|
||||||
|
{
|
||||||
|
return Validate::num();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validateNumInput()
|
||||||
|
{
|
||||||
|
return Validate::num(Validate::TRIGGER_BLUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validateDate()
|
||||||
|
{
|
||||||
|
return Validate::date();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validateFrame()
|
||||||
|
{
|
||||||
|
return self::ValidateArr();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user