Commit 83c464ac authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Fixing #93, test_type value controls show/hide of cell_line_name, and emptiness during clean

parent cc1c9156
Pipeline #24473 failed with stages
in 9 minutes and 8 seconds
......@@ -969,6 +969,10 @@ class TestActivityDescriptionForm(forms.ModelForm):
"is_primary": forms.HiddenInput(),
}
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.fields["test_type"].widget.attrs["onchange"]="test_type_changed(this);"
def has_changed(self):
"""
Test if the form has changed, we consider that it has not changed if it is not linked to an actual instance and
......@@ -984,6 +988,12 @@ class TestActivityDescriptionForm(forms.ModelForm):
return False
return super().has_changed()
def clean(self):
cleaned_data = super().clean()
if "test_type" in cleaned_data and cleaned_data["test_type"] is not "CELL":
cleaned_data["cell_line_name"] = ""
return cleaned_data
def save(self, commit=True):
"""
Before an actual save, we set the foreign key that have been created in the meantime from unique identifier
......
function test_type_changed(source){
var cell_line_input = document.getElementById(source.id.replace("test_type","cell_line_name")).parentNode;
if (source.value=="CELL"){
cell_line_input.style.display = '';
}else{
cell_line_input.style.display = 'none';
}
}
\ No newline at end of file
......@@ -6,6 +6,11 @@
{% block extra_js %}
{{block.super}}
<script src="{% sstatic '/js/wizard_formset_with_nested_formset.js'%}"></script>
{% with wizard.management_form|get_item:"current_step" as current_step %}
{% with "/js/"|add:current_step.value|add:".js" as js_url %}
<script src="{% sstatic js_url %}"></script>
{%endwith%}
{%endwith%}
{% endblock extra_js %}
......
......@@ -34,6 +34,10 @@ def bootstrap(object):
return mark_safe("".join(bootstrap_core(object)))
@register.filter
def get_item(d, key):
return d[key]
def bootstrap_core(object):
ret = []
if isinstance(object, forms.BoundField):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment