From 4ea5d7a631226502730a2c8fd5c598154afac736 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 5 Feb 2021 10:36:03 -0500 Subject: [PATCH] A couple of new convenience methods added to InputfieldWrapper --- wire/core/InputfieldWrapper.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index 42db8129..b90c2793 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -1255,6 +1255,8 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre /** * Given an Inputfield name, return the child Inputfield or NULL if not found. * + * This traverses all children recursively to find the requested Inputfield. + * * This is the same as the `InputfieldWrapper::get()` method except that it can * only return Inputfield or null, and has no crossover with other settings, * properties or API variables. @@ -1280,6 +1282,37 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre return $inputfield; } + /** + * Shorter alias of getChildByName() + * + * #pw-group-retrieval-and-traversal + * + * @param string $name + * @return Inputfield|null + * @since 3.0.172 + * + */ + public function getByName($name) { + return $this->getChildByName($name); + } + + /** + * Get value of Inputfield by name + * + * This traverses all children recursively to find the requested Inputfield, + * and get the value attribute from it. A value of null is returned if the + * Inputfield cannot be found. + * + * @param string $name + * @return string|int|float|bool|array|object|null + * @since 3.0.172 + * + */ + public function getValueByName($name) { + $inputfield = $this->getChildByName($name); + return $inputfield ? $inputfield->val() : null; + } + /** * Enables foreach() of the children of this class *