diff --git a/vendor/xaboy/form-builder/src/Form.php b/vendor/xaboy/form-builder/src/Form.php index 2067369d..e528a1d3 100644 --- a/vendor/xaboy/form-builder/src/Form.php +++ b/vendor/xaboy/form-builder/src/Form.php @@ -60,7 +60,6 @@ class Form */ protected $loadCityData = false; - /** * 三级联动 加载省市区数据 * @var bool @@ -86,7 +85,7 @@ class Form //iview 版本 2.14.3 'iview-css' => '', 'iview' => '', - //form-create 版本 1.3.1 + //form-create 版本 1.3.3 'form-create' => '', 'city-data' => '', 'city-area-data' => '' @@ -109,6 +108,12 @@ class Form */ protected $action = ''; + /** + * 表单id + * @var string + */ + protected $id = ''; + /** * 提交方式 * @var string @@ -135,12 +140,28 @@ class Form * @param string $action 提交地址 * @param array $components 组件 */ - public function __construct($action, array $components = []) + public function __construct($action = '', array $components = []) { $this->components($components); $this->action = $action; } + /** + * @return bool + */ + public function isLoadCityData() + { + return $this->loadCityData; + } + + /** + * @return bool + */ + public function isLoadCityAreaData() + { + return $this->loadCityAreaData; + } + /** * @param array $components * @return $this @@ -193,6 +214,24 @@ class Form return $this; } + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + /** * @return string @@ -275,6 +314,7 @@ class Form if(!isset($this->components[$field])) $this->fields[] = $field; $this->components[$field] = $component; + $this->checkLoadData($component); return $this; } @@ -289,9 +329,27 @@ class Form if(!isset($this->components[$field])) array_unshift($this->fields, $field); $this->components[$field] = $component; + $this->checkLoadData($component); return $this; } + /** + * @param FormComponentDriver $component + */ + protected function checkLoadData(FormComponentDriver $component) + { + if( + $component instanceof Cascader + && ($this->loadCityData == false || $this->loadCityAreaData == false) + ){ + $type = $component->getType(); + if ($type == Cascader::TYPE_CITY) + $this->loadCityData = true; + else if ($type == Cascader::TYPE_CITY_AREA) + $this->loadCityAreaData = true; + } + } + /** * 获得表单规则 * @return array @@ -303,15 +361,6 @@ class Form $component = $this->components[$field]; if (!($component instanceof FormComponentDriver)) continue; - - $loadData = $this->loadCityData == true && $this->loadCityAreaData == true; - if ($loadData == false && $component instanceof Cascader) { - $type = $component->getType(); - if ($type == Cascader::TYPE_CITY) - $this->loadCityData = true; - else if ($type == Cascader::TYPE_CITY_AREA) - $this->loadCityAreaData = true; - } $rules[] = $component->build(); } return $rules; @@ -326,7 +375,6 @@ class Form { ob_start(); $form = $this; - $rule = $this->getRules(); require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'form.php'; $html = ob_get_clean(); return $html; @@ -349,7 +397,6 @@ class Form { ob_start(); $form = $this; - $rule = $this->getRules(); require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'formScript.php'; $script = ob_get_clean(); return $script; @@ -379,7 +426,7 @@ class Form /** * 生成表单快捷方法 - * @param $action + * @param string $action * @param array $components * @return Form */