from django import template

register = template.Library()

class_converter = {
    "textinput":"textinput textInput",
    "fileinput":"fileinput fileUpload",
    "passwordinput":"passwordinput textInput"
}

@register.filter
def is_checkbox(field):
    return field.field.widget.__class__.__name__.lower() == "checkboxinput"

@register.filter
def with_class(field):
    class_name = field.field.widget.__class__.__name__.lower()
    class_name = class_converter.get(class_name, class_name)
    if "class" in field.field.widget.attrs:
        css_class = field.field.widget.attrs['class']
        if field.field.widget.attrs['class'].find(class_name) == -1:
            css_class += " %s" % (class_name,)
    else:
        css_class = class_name

    return field.as_widget(attrs={'class': css_class})    






from django import template

register = template.Library()

class_converter = {
    "textinput":"textinput textInput",
    "fileinput":"fileinput fileUpload",
    "passwordinput":"textinput textInput",
>>>>>>> f85af74... Convert css class of PasswordInput widget:uni_form/templatetags/uni_form_field.py
}

@register.filter
def is_checkbox(field):
    return field.field.widget.__class__.__name__.lower() == "checkboxinput"

@register.filter
def with_class(field):
    class_name = field.field.widget.__class__.__name__.lower()
    class_name = class_converter.get(class_name, class_name)
    if "class" in field.field.widget.attrs:
        css_class = field.field.widget.attrs['class']
        if field.field.widget.attrs['class'].find(class_name) == -1:
            css_class += " %s" % (class_name,)
    else:
        css_class = class_name

    return field.as_widget(attrs={'class': css_class})    






Convert css class of PasswordInput widget