protected function setErrorField($name, $value, $messages, $arrayIndex = null)
    {
        // Loop through all errors
        foreach ($messages as $errorType => $error) {
            // When the validation messages are about an array, they are set in a sub array (validation_errors)
            if (is_numeric($errorType) && is_array($error) && isset($error['validation_errors'])) {
                // Array index is 1 based so deduct one to create 0 based index
                $arrayIndex = ((int) $errorType) - 1;
                $this->setErrorField(
                    $name,
                    isset($value[$arrayIndex]) ? $value[$arrayIndex] : null,
                    $error['validation_errors'],
                    $arrayIndex
                );
            } elseif (is_array($error)) {
                // When there is an array of errors returned, handle them recursively
                $this->setErrorField($name, $value, $error, $arrayIndex);
            } else {
                // Add error field with all information
                $this->errorFields[] = new ErrorField($name, $value, $errorType, $error, $arrayIndex);
            }
        }
    }