@@ -103,10 +103,10 @@ public function setValues($data, bool $erase = false)
103103 /**
104104 * Returns the values submitted by the form.
105105 * @param string|object|null $returnType 'array' for array
106-
106+ * @param Control[]|null $controls
107107 * @return object|array
108108 */
109- public function getValues ($ returnType = null )
109+ public function getValues ($ returnType = null , array $ controls = null )
110110 {
111111 if ($ returnType === self ::ARRAY || $ returnType === true || $ this ->mappedType === self ::ARRAY ) {
112112 $ returnType = self ::ARRAY ;
@@ -123,14 +123,18 @@ public function getValues($returnType = null)
123123 $ rc = new \ReflectionClass ($ obj );
124124 foreach ($ this ->getComponents () as $ name => $ control ) {
125125 $ name = (string ) $ name ;
126- if ($ control instanceof Control && !$ control ->isOmitted ()) {
126+ if (
127+ $ control instanceof Control
128+ && !$ control ->isOmitted ()
129+ && ($ controls === null || in_array ($ control , $ controls , true ))
130+ ) {
127131 $ obj ->$ name = $ control ->getValue ();
128132
129133 } elseif ($ control instanceof self) {
130134 $ type = $ returnType === self ::ARRAY && !$ control ->mappedType
131135 ? self ::ARRAY
132136 : ($ rc ->hasProperty ($ name ) ? Nette \Utils \Reflection::getPropertyType ($ rc ->getProperty ($ name )) : null );
133- $ obj ->$ name = $ control ->getValues ($ type );
137+ $ obj ->$ name = $ control ->getValues ($ type, $ controls );
134138 }
135139 }
136140
@@ -172,7 +176,7 @@ public function isValid(): bool
172176 */
173177 public function validate (array $ controls = null ): void
174178 {
175- foreach ($ controls === null ? $ this ->getComponents () : $ controls as $ control ) {
179+ foreach ($ controls ?? $ this ->getComponents () as $ control ) {
176180 if ($ control instanceof Control || $ control instanceof self) {
177181 $ control ->validate ();
178182 }
0 commit comments