From f396c20f6f5af60dd2a6fee2b12eca0d0804c308 Mon Sep 17 00:00:00 2001 From: Munim Munna <6266677+monim67@users.noreply.github.com> Date: Sun, 5 Jan 2020 20:04:16 +0600 Subject: [PATCH] Added value_template_string property to BaseInput To prevent the loss of original value passed to BaseInput sub-classes due to overwrite in render method, the value is stored into value_template_string property. --- crispy_forms/layout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crispy_forms/layout.py b/crispy_forms/layout.py index d2dff8cbf..3362c4c13 100644 --- a/crispy_forms/layout.py +++ b/crispy_forms/layout.py @@ -176,7 +176,7 @@ class BaseInput(TemplateNameMixin): def __init__(self, name, value, **kwargs): self.name = name - self.value = value + self.value_template_string = value self.id = kwargs.pop('css_id', '') self.attrs = {} @@ -191,7 +191,7 @@ def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwarg Renders an `` if container is used as a Layout object. Input button value can be a variable in context. """ - self.value = Template(str(self.value)).render(context) + self.value = Template(str(self.value_template_string)).render(context) template = self.get_template_name(template_pack) context.update({'input': self})