def parse_timedelta_from_form(data_dict, key_root):
    """Parse values from a timedelta form element, and return the value in
    minutes

    Parameters
    ----------
    data_dict: dict
        Dictionary of posted form data

    key_root: string
        The shared part of the name attribute of the inputs to parse.
        e.g. 'lead_time' will parse and concatenate 'lead_time_number'
        and 'lead_time_units'

    Returns
    -------
    int
        The number of minutes in the Timedelta.

    Raises
    ------
    ValueError
        If the units field is not one of 'minutes', 'hours' or 'days', or if
        the number field is not a valid integer.
    """
    # Cast first to float to handle case where user has entered an integer as
    # a floating point number.
    value = int(float(data_dict[f'{key_root}_number']))
    units = data_dict[f'{key_root}_units']
    if units == 'minutes':
        return value
    elif units == 'hours':
        return value * 60
    elif units == 'days':
        return value * 1440
    else:
        raise ValueError(f'Invalid units in {key_root} field.')