diff --git a/edivorce/apps/core/templatetags/__init__.py b/edivorce/apps/core/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/edivorce/apps/core/templatetags/input_option.py b/edivorce/apps/core/templatetags/input_option.py new file mode 100644 index 00000000..4e6d68e8 --- /dev/null +++ b/edivorce/apps/core/templatetags/input_option.py @@ -0,0 +1,45 @@ +from django import template + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def input_option(context, type, name='', value='', **kwargs): + """ + Usage: when specifying data attributes in templates, use "data_" intead of "data-". + """ + if type == "textarea": + tag = ['') + else: + # set initial value for textbox + if type == "text": + value = context.get(name, '') + tag = ['') + + return ''.join(tag) + + +def additional_attributes(tag, **kwargs): + for key, data_val in kwargs.items(): + if str.startswith(key, 'data_'): + key = str.replace(key, 'data_', 'data-') + tag.append(' ' + key + '="' + data_val + '"') + return tag