Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
1 merge request!13Master
Pipeline #24473 failed
...@@ -969,6 +969,10 @@ class TestActivityDescriptionForm(forms.ModelForm): ...@@ -969,6 +969,10 @@ class TestActivityDescriptionForm(forms.ModelForm):
"is_primary": forms.HiddenInput(), "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): 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 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): ...@@ -984,6 +988,12 @@ class TestActivityDescriptionForm(forms.ModelForm):
return False return False
return super().has_changed() 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): def save(self, commit=True):
""" """
Before an actual save, we set the foreign key that have been created in the meantime from unique identifier 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 @@ ...@@ -6,6 +6,11 @@
{% block extra_js %} {% block extra_js %}
{{block.super}} {{block.super}}
<script src="{% sstatic '/js/wizard_formset_with_nested_formset.js'%}"></script> <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 %} {% endblock extra_js %}
......
...@@ -34,6 +34,10 @@ def bootstrap(object): ...@@ -34,6 +34,10 @@ def bootstrap(object):
return mark_safe("".join(bootstrap_core(object))) return mark_safe("".join(bootstrap_core(object)))
@register.filter
def get_item(d, key):
return d[key]
def bootstrap_core(object): def bootstrap_core(object):
ret = [] ret = []
if isinstance(object, forms.BoundField): if isinstance(object, forms.BoundField):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment