Skip to content

Commit

Permalink
验证器bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
lphkxd committed Oct 13, 2020
1 parent cf8d8b6 commit 87104ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace HPlus\UI;

use HPlus\UI\Exception\BusinessException;
use HPlus\UI\Form\FormTab;
use HPlus\UI\Layout\Row;
use HPlus\Validate\Validate;
Expand All @@ -36,6 +37,7 @@
class Form extends Component
{
use TraitFormAttrs, HasHooks, HasRef;

protected $componentName = "Form";

const REMOVE_FLAG_NAME = '_remove_';
Expand Down Expand Up @@ -236,6 +238,7 @@ protected function items($items = [])

}


/**
* 自定义表单动作
* @param $closure
Expand Down Expand Up @@ -401,11 +404,13 @@ protected function validatorData($data)
{
$rules = [];
$ruleMessages = [];
$field = [];
/* @var FormItem $formItem */
foreach ($this->formItems as $formItem) {
if (empty($formItem->getServeRole())) {
continue;
}
$field[$formItem->getField()] =$formItem->getLabel();
$rules[$formItem->getField()] = $formItem->getServeRole();
$messages = $formItem->getServeRulesMessage();
if (is_array($messages)) {
Expand All @@ -416,13 +421,9 @@ protected function validatorData($data)
}
$rules = array_merge($rules, $this->addRule);
$ruleMessages = array_merge($ruleMessages, $this->addRuleMessage);
$validator = new Validate();
$validator->message($ruleMessages);
$validator->failException(true);
try {
$validator->check($data, $rules);
} catch (\Throwable $exception) {
throw new ValidateException((int)$exception->getCode(), (string)$exception->getMessage());
$validator = new Validate($rules, $ruleMessages, $field);
if ($validator->check($data) !== true) {
throw new ValidateException(422, (string)$validator->getError());
}
}

Expand Down Expand Up @@ -867,6 +868,7 @@ public function jsonSerialize()
if ($this->isGetData) {
return $this->editData($this->getResourceId());
}

return array_filter([
'componentName' => $this->componentName,
'action' => $this->getAction(),
Expand Down
10 changes: 10 additions & 0 deletions src/Form/FormItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FormItem extends Component

protected $prop;
protected $label;

protected $hideLabel = false;
protected $field;
protected $labelWidth;
Expand Down Expand Up @@ -100,6 +101,15 @@ public function __construct($prop, $label, $field)
$this->component = Input::make();
}


/**
* @return mixed
*/
public function getLabel()
{
return $this->label;
}

protected function formatLabel($label)
{
if ($label) {
Expand Down

0 comments on commit 87104ad

Please sign in to comment.