diff --git a/atst/forms/financial.py b/atst/forms/financial.py
index d8e21653..21fde2c9 100644
--- a/atst/forms/financial.py
+++ b/atst/forms/financial.py
@@ -1,7 +1,7 @@
import re
from wtforms.fields.html5 import EmailField
from wtforms.fields import StringField, SelectField
-from wtforms.validators import Required, Email, InputRequired
+from wtforms.validators import Required, Email, InputRequired, Optional
from atst.domain.exceptions import NotFoundError
from atst.domain.pe_numbers import PENumbers
@@ -55,6 +55,12 @@ def validate_pe_id(field, existing_request):
class FinancialForm(ValidatedForm):
+ def validate(self, *args, **kwargs):
+ if self.funding_type.data == "OTHER":
+ self.funding_type_other.validators.append(Required())
+ return super().validate(*args, **kwargs)
+
+
def perform_extra_validation(self, existing_request):
valid = True
if not existing_request or existing_request.get("pe_id") != self.pe_id.data:
@@ -110,9 +116,7 @@ class FinancialForm(ValidatedForm):
validators=[InputRequired()]
)
- funding_type_other = StringField(
- "If other, please specify", validators=[Required()]
- )
+ funding_type_other = StringField("If other, please specify")
clin_0001 = StringField(
"
- CLIN 0001
- - Unclassified IaaS and PaaS Amount
",
diff --git a/js/components/forms/financial.js b/js/components/forms/financial.js
new file mode 100644
index 00000000..2a1fb43b
--- /dev/null
+++ b/js/components/forms/financial.js
@@ -0,0 +1,41 @@
+import optionsinput from '../options_input'
+import textinput from '../text_input'
+
+export default {
+ name: 'financial',
+
+ components: {
+ optionsinput,
+ textinput,
+ },
+
+ props: {
+ initialData: {
+ type: Object,
+ default: () => ({})
+ }
+ },
+
+ data: function () {
+ const {
+ funding_type = ""
+ } = this.initialData
+
+ return {
+ funding_type
+ }
+ },
+
+ mounted: function () {
+ this.$root.$on('field-change', this.handleFieldChange)
+ },
+
+ methods: {
+ handleFieldChange: function (event) {
+ const { value, name } = event
+ if (typeof this[name] !== undefined) {
+ this[name] = value
+ }
+ },
+ }
+}
diff --git a/js/index.js b/js/index.js
index afe6961d..4ecd6aa7 100644
--- a/js/index.js
+++ b/js/index.js
@@ -7,6 +7,7 @@ import textinput from './components/text_input'
import checkboxinput from './components/checkbox_input'
import DetailsOfUse from './components/forms/details_of_use'
import poc from './components/forms/poc'
+import financial from './components/forms/financial'
Vue.use(VTooltip)
@@ -19,6 +20,7 @@ const app = new Vue({
checkboxinput,
DetailsOfUse,
poc,
+ financial,
},
methods: {
closeModal: function(name) {
diff --git a/templates/requests/financial_verification.html b/templates/requests/financial_verification.html
index 40f38af0..5f4c14e7 100644
--- a/templates/requests/financial_verification.html
+++ b/templates/requests/financial_verification.html
@@ -6,6 +6,7 @@
{% block content %}
+
+
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/tests/forms/test_financial.py b/tests/forms/test_financial.py
index c24c742d..62cea8ec 100644
--- a/tests/forms/test_financial.py
+++ b/tests/forms/test_financial.py
@@ -1,6 +1,6 @@
import pytest
-from atst.forms.financial import suggest_pe_id
+from atst.forms.financial import suggest_pe_id, FinancialForm
@pytest.mark.parametrize("input_,expected", [
@@ -12,3 +12,21 @@ from atst.forms.financial import suggest_pe_id
])
def test_suggest_pe_id(input_, expected):
assert suggest_pe_id(input_) == expected
+
+
+def test_funding_type_other_not_required_if_funding_type_is_not_other():
+ form_data = {
+ "funding_type": "PROC"
+ }
+ form = FinancialForm(data=form_data)
+ form.validate()
+ assert "funding_type_other" not in form.errors
+
+
+def test_funding_type_other_required_if_funding_type_is_other():
+ form_data = {
+ "funding_type": "OTHER"
+ }
+ form = FinancialForm(data=form_data)
+ form.validate()
+ assert "funding_type_other" in form.errors