def flatten_errors(errors, prefix=""):
    """Return list of errors from form errors."""
    error_list = []
    if isinstance(errors, dict):
        for key, value in errors.items():
            # Recurse to handle subforms.
            error_list += flatten_errors(value, prefix=f"{prefix}{key}-")
    elif isinstance(errors, list) and isinstance(errors[0], dict):
        for idx, error in enumerate(errors):
            error_list += flatten_errors(error, prefix=f"{prefix}{idx}-")
    elif isinstance(errors, list):
        error_list.append({"text": errors[0], "href": "#{}".format(prefix.rstrip("-"))})
    else:
        error_list.append({"text": errors, "href": "#{}".format(prefix.rstrip("-"))})
    return error_list