LSform / LSformRule: only show default error message if rule does not trigger itself an error

This commit is contained in:
Benjamin Renard 2021-07-19 16:46:44 +02:00
parent 2a0981a21e
commit 3298320b3d
2 changed files with 13 additions and 19 deletions

View file

@ -252,20 +252,14 @@ class LSattribute extends LSlog_staticLoggerClass {
else {
$check_data = $this -> getConfig('check_data', array());
if(is_array($check_data)) {
foreach ($check_data as $rule => $rule_infos) {
if((!$form -> isRuleRegistered($rule))&&($rule!='')) {
LSerror :: addErrorCode('LSattribute_03',array('attr' => $this->name,'rule' => $rule));
foreach ($check_data as $rule => $rule_options) {
// Check rule
if(!is_empty($rule) && !$form -> isRuleRegistered($rule)) {
LSerror :: addErrorCode('LSattribute_03', array('attr' => $this->name, 'rule' => $rule));
return;
}
if(!isset($rule_infos['msg'])) {
$rule_infos['msg']=getFData(_('The value of field %{label} is invalid.'),$this -> getLabel());
}
else {
$rule_infos['msg']=__($rule_infos['msg']);
}
if(!isset($rule_infos['params']))
$rule_infos['params']=NULL;
$form -> addRule($this -> name,$rule,array('msg' => $rule_infos['msg'], 'params' => $rule_infos['params']));
// Add rule to form
$form -> addRule($this -> name, $rule, (is_array($rule_options)?$rule_options:array()));
}
}
else {

View file

@ -584,22 +584,22 @@ class LSform extends LSlog_staticLoggerClass {
*
* @retval boolean
*/
public function addRule($element, $rule, $options=array()) {
public function addRule($element, $rule, $options=null) {
if ( isset($this ->elements[$element]) ) {
if ($this -> isRuleRegistered($rule)) {
$this -> _rules[$element][]=array(
'name' => $rule,
'options' => $options
);
$this -> _rules[$element][] = array(
'name' => $rule,
'options' => (is_array($options)?$options:array()),
);
return true;
}
else {
LSerror :: addErrorCode('LSattribute_03',array('attr' => $element,'rule'=>$rule));
LSerror :: addErrorCode('LSattribute_03', array('attr' => $element, 'rule' => $rule));
return;
}
}
else {
LSerror :: addErrorCode('LSform_04',array('element' => $element));
LSerror :: addErrorCode('LSform_04', array('element' => $element));
return;
}
}