mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 09:14:58 +02:00
Update InputfieldWrapper to have an error method that enables you get get Inputfields having errors rather than just getting error messages.
This commit is contained in:
@@ -1910,6 +1910,20 @@ abstract class Inputfield extends WireData implements Module {
|
|||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear errors from this Inputfield
|
||||||
|
*
|
||||||
|
* This is the same as `$inputfield->getErrors(true);` but has no return value.
|
||||||
|
*
|
||||||
|
* #pw-group-states
|
||||||
|
*
|
||||||
|
* @since 3.0.205
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function clearErrors() {
|
||||||
|
$this->getErrors(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does this Inputfield have the requested property or attribute?
|
* Does this Inputfield have the requested property or attribute?
|
||||||
*
|
*
|
||||||
|
@@ -937,9 +937,9 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
|||||||
if(!isset($ffAttrs['id'])) $ffAttrs['id'] = 'wrap_' . $inputfield->attr('id');
|
if(!isset($ffAttrs['id'])) $ffAttrs['id'] = 'wrap_' . $inputfield->attr('id');
|
||||||
$ffAttrs['class'] = str_replace('Inputfield_ ', '', $ffAttrs['class']);
|
$ffAttrs['class'] = str_replace('Inputfield_ ', '', $ffAttrs['class']);
|
||||||
$wrapClass = $inputfield->getSetting('wrapClass');
|
$wrapClass = $inputfield->getSetting('wrapClass');
|
||||||
if($wrapClass) $ffAttrs['class'] .= " " . $wrapClass;
|
if($wrapClass) $ffAttrs['class'] = trim("$ffAttrs[class] $wrapClass");
|
||||||
foreach($inputfield->wrapAttr() as $k => $v) {
|
foreach($inputfield->wrapAttr() as $k => $v) {
|
||||||
if(!empty($ffAttrs[$k])) {
|
if($k === 'class' && !empty($ffAttrs[$k])) {
|
||||||
$ffAttrs[$k] .= " $v";
|
$ffAttrs[$k] .= " $v";
|
||||||
} else {
|
} else {
|
||||||
$ffAttrs[$k] = $v;
|
$ffAttrs[$k] = $v;
|
||||||
@@ -1306,8 +1306,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
|||||||
*
|
*
|
||||||
* Should only be called after `InputfieldWrapper::processInput()`.
|
* Should only be called after `InputfieldWrapper::processInput()`.
|
||||||
*
|
*
|
||||||
* #pw-group-input
|
* #pw-group-errors
|
||||||
* #pw-group-retrieval-and-traversal
|
|
||||||
*
|
*
|
||||||
* @param bool $clear Specify true to clear out the errors (default=false).
|
* @param bool $clear Specify true to clear out the errors (default=false).
|
||||||
* @return array Array of error strings
|
* @return array Array of error strings
|
||||||
@@ -1326,6 +1325,33 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
|||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Inputfield objects that have errors
|
||||||
|
*
|
||||||
|
* #pw-group-errors
|
||||||
|
*
|
||||||
|
* @return Inputfield[]
|
||||||
|
* @since 3.0.205
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getErrorInputfields() {
|
||||||
|
$a = array();
|
||||||
|
if(count(parent::getErrors())) {
|
||||||
|
$name = $this->attr('name');
|
||||||
|
$a[$name] = $this;
|
||||||
|
}
|
||||||
|
foreach($this->children() as $child) {
|
||||||
|
/** @var Inputfield $child */
|
||||||
|
if($child instanceof InputfieldWrapper) {
|
||||||
|
$a = array_merge($a, $child->getErrorInputfields());
|
||||||
|
} else if(count($child->getErrors())) {
|
||||||
|
$name = $child->attr('name');
|
||||||
|
$a[$name] = $child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $a;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all children Inputfield objects
|
* Return all children Inputfield objects
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user