def get_widget_by_id(form, widget_id):
    """Get a widget by it's rendered DOM element id."""
    # convert the id to a name
    name = widget_id.replace('-', '.')
    prefix = form.prefix + form.widgets.prefix
    if not name.startswith(prefix):
        raise ValueError("Name %r must start with prefix %r" % (name, prefix))
    short_name = name[len(prefix):]
    return form.widgets.get(short_name, None)