Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BaseInput subclasses value can now be set to a context variable

  • Loading branch information...
commit d9785ec27ccc81f28af9833e5e81fa942f745b3e 1 parent a4ea988
Miguel Araujo authored
Showing with 9 additions and 4 deletions.
  1. +3 −1 crispy_forms/layout.py
  2. +6 −3 crispy_forms/tests/tests.py
4 crispy_forms/layout.py
View
@@ -214,8 +214,10 @@ def __init__(self, name, value, **kwargs):
def render(self, form, form_style, context):
"""
- Renders an `<input />` if container is used as a Layout object
+ Renders an `<input />` if container is used as a Layout object.
+ Input button value can be a variable in context.
"""
+ self.value = Template(unicode(self.value)).render(context)
return render_to_string(self.template, Context({'input': self}))
9 crispy_forms/tests/tests.py
View
@@ -623,7 +623,8 @@ def test_second_layout_multifield_column_buttonholder_submit_div(self):
css_class = "columns",
),
ButtonHolder(
- Submit('Save the world', 'Save', css_class='button white', data_id='test', data_name='test'),
+ Submit('Save the world', '{{ value_var }}', css_class='button white', data_id='test', data_name='test'),
+ Submit('store', 'Store results')
),
Div(
'password1',
@@ -639,7 +640,7 @@ def test_second_layout_multifield_column_buttonholder_submit_div(self):
{% load crispy_forms_tags %}
{% crispy form form_helper %}
""")
- c = Context({'form': TestForm(), 'form_helper': form_helper})
+ c = Context({'form': TestForm(), 'form_helper': form_helper, 'value_var': "Save"})
html = template.render(c)
self.assertTrue('multiField' in html)
@@ -655,11 +656,13 @@ def test_second_layout_multifield_column_buttonholder_submit_div(self):
self.assertTrue('data-id="test"' in html)
self.assertTrue('data-name="test"' in html)
self.assertTrue('name="save-the-world"' in html)
+ self.assertTrue('value="Save"' in html)
+ self.assertTrue('name="store"' in html)
+ self.assertTrue('value="Store results"' in html)
self.assertTrue('id="custom-div"' in html)
self.assertTrue('class="customdivs"' in html)
self.assertTrue('test-markup="123"' in html)
-
def test_layout_within_layout(self):
form_helper = FormHelper()
form_helper.add_layout(
Please sign in to comment.
Something went wrong with that request. Please try again.