From 3c7bf533c5b7d282c94b4174dfc948fe2b12111f Mon Sep 17 00:00:00 2001 From: fredkingham Date: Thu, 27 Apr 2017 15:35:06 +0100 Subject: [PATCH] add test for every template tag to make sure they honour the change argument, improve the documentation --- doc/docs/reference/form_templatetags.md | 8 ++++++- opal/tests/test_templatetags_forms.py | 30 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/doc/docs/reference/form_templatetags.md b/doc/docs/reference/form_templatetags.md index 58d0a5fca..f00cde001 100644 --- a/doc/docs/reference/form_templatetags.md +++ b/doc/docs/reference/form_templatetags.md @@ -15,6 +15,7 @@ Keywords: [Inference from subrecord fields](#inference-from-subrecord-fields) * `label` The Label with which to describe this field * `model` The model which we are editing (This is a string that references an in-scope Angular variable) +* `change` A javascript function that fires if the field has changed * `disabled` If this exists, we use this as the expression for the ng-disabled directive * `element_name` If this exists this is an Angular expression that is set to the 'name' attribute of the html element @@ -29,6 +30,7 @@ Keywords: [Inference from subrecord fields](#inference-from-subrecord-fields) * `label` The Label with which to describe this field * `model` The model which we are editing (This is a string that references an in-scope Angular variable) +* `change` A javascript function that fires if the field has changed * `show` A string that contains an Angular expression for the ng-show directive * `hide` A string that contains an Angular expression for the ng-hide directive * `required` Label to show when we're required @@ -46,7 +48,7 @@ Keywords: * `date_label` The Label with which to describe the date field (defaults to 'Date') * `time_label` The Label with which to describe the date field (defaults to 'Time') * `model` The model which we are editing (This is a string that references an in-scope Angular variable) -* `change` an Angular directive that fires on change +* `change` A javascript function that fires if the field has changed * `element_name` If this exists this is an Angular expression that is set to the 'name' attribute of the html datetime picker element @@ -61,6 +63,7 @@ Keywords: [Inference from subrecord fields](#inference-from-subrecord-fields) * `label` The Label with which to describe this field * `model` The model which we are editing (This is a string that references an in-scope Angular variable) +* `change` A javascript function that fires if the field has changed * `show` A string that contains an Angular expression for the ng-show directive * `hide` A string that contains an Angular expression for the ng-hide directive * `lookuplist` an Angular expression that evaluates to an array containing the lookuplist values @@ -89,6 +92,7 @@ Keywords: * `field` a string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% radio field="DogOwner.dog" %} * `label` The Label with which to describe this input * `model` The model which we are editing (This is a string that references an in-scope Angular variable) +* `change` A javascript function that fires if the field has changed * `show` A string that contains an Angular expression for the ng-show directive * `hide` A string that contains an Angular expression for the ng-hide directive * `lookuplist` an Angular expression that evaluates to an array containing the radio values @@ -104,6 +108,7 @@ Keywords: * `field` a string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% select field="DogOwner.dog" %} * `label` The Label with which to describe this input * `model` The model which we are editing (This is a string that references an in-scope Angular variable) +* `change` A javascript function that fires if the field has changed * `show` A string that contains an Angular expression for the ng-show directive * `hide` A string that contains an Angular expression for the ng-hide directive * `lookuplist` an Angular expression that evaluates to an array containing the radio values @@ -121,6 +126,7 @@ Keywords: * `field` a string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% textarea field="DogOwner.dog" %} * `label` The Label with which to describe this input * `model` The model which we are editing (This is a string that references an in-scope Angular variable) +* `change` A javascript function that fires if the field has changed * `show` A string that contains an Angular expression for the ng-show directive * `hide` A string that contains an Angular expression for the ng-hide directive * `element_name` If this exists this is an Angular expression that is set to the 'name' attribute of the html element diff --git a/opal/tests/test_templatetags_forms.py b/opal/tests/test_templatetags_forms.py index 9e491116b..2f22b97b2 100644 --- a/opal/tests/test_templatetags_forms.py +++ b/opal/tests/test_templatetags_forms.py @@ -109,6 +109,11 @@ def test_element_name(self): rendered = tpl.render(Context({})) self.assertIn('name="[[ onions ]]"', rendered) + def test_change(self): + tpl = Template('{% load forms %}{% textarea label="hai" change="doStuff" model="bai" element_name="onions"%}') + rendered = tpl.render(Context({})) + self.assertIn('ng-change="doStuff"', rendered) + class InputTest(TestCase): @@ -196,6 +201,11 @@ def test_required_error(self): rendered = tpl.render(Context({})) self.assertIn('(form[onions].$dirty || form.$submitted) && form[onions].$error.required', rendered) + def test_change(self): + tpl = Template('{% load forms %}{% input label="hai" change="doStuff" model="bai" element_name="onions"%}') + rendered = tpl.render(Context({})) + self.assertIn('ng-change="doStuff"', rendered) + class CheckboxTestCase(TestCase): @@ -215,6 +225,11 @@ def test_set_element_id(self): rendered = tpl.render(Context({})) self.assertIn('id="checkbox_[[ onions ]]"', rendered) + def test_change(self): + tpl = Template('{% load forms %}{% checkbox label="hai" change="doStuff" model="bai" element_name="onions"%}') + rendered = tpl.render(Context({})) + self.assertIn('ng-change="doStuff"', rendered) + class DatepickerTestCase(TestCase): @@ -254,6 +269,11 @@ def test_show(self): rendered = tpl.render(Context({})) self.assertIn('ng-hide="onions"', rendered) + def test_change(self): + tpl = Template('{% load forms %}{% datepicker label="hai" change="doStuff" model="bai" element_name="onions"%}') + rendered = tpl.render(Context({})) + self.assertIn('ng-change="doStuff"', rendered) + class DateTimePickerTestCase(TestCase): def test_generic(self): @@ -321,6 +341,11 @@ def test_element_name_required(self): rendered = tpl.render(Context({})) self.assertIn('form.$submitted && form[onions].$error.required"', rendered) + def test_change(self): + tpl = Template('{% load forms %}{% radio label="hai" change="doStuff" model="bai" element_name="onions"%}') + rendered = tpl.render(Context({})) + self.assertIn('ng-change="doStuff"', rendered) + class SelectTestCase(TestCase): @@ -370,6 +395,11 @@ def test_element_name_required(self): rendered = tpl.render(Context({})) self.assertIn('"form.$submitted && form[onions].$error.required"', rendered) + def test_change(self): + tpl = Template('{% load forms %}{% select label="hai" change="doStuff" model="bai" element_name="onions"%}') + rendered = tpl.render(Context({})) + self.assertIn('ng-change="doStuff"', rendered) + class StaticTestCase(TestCase):