bugs in multiple checkbox of SWAT res type
@mohamedmorsy @jsadler2 
We first found this bug in WebApp res type. Initially some code of the multiple checkbox implementation was copied from the SWAT res type, so we suspect SWAT is having the same bug, and looks like it does.

The bug is: 1) user first checks a model objective and clicks "Save", 
2) then un-checks all options and clicks "Save", 
3) then checks some options and clicks "Save", an error will occur "Error! Metadata failed to update".

The reason is the "update" function in models.py removes the metadata obj if no option is checked: https://github.com/hydroshare/hydroshare/blob/develop/hs_swat_modelinstance/models.py#L86.
When user tries to check some options again, the "Save" button calls "update" the function, but at this time nothing can be updated as the metadata obj is gone already.

In webapp res type we just removed the corresponding lines 85, 86 in your swat code, and looks like it does not break anything in webapp res app so far.

diff --git a/hs_core/signals.py b/hs_core/signals.py
index 32231c309..7509c1e09 100644
--- a/hs_core/signals.py
+++ b/hs_core/signals.py
@@ -8,7 +8,8 @@ pre_delete_file_from_resource = django.dispatch.Signal(providing_args=['file', '
 post_add_files_to_resource = django.dispatch.Signal(providing_args=['files', 'resource'])
 
 pre_metadata_element_create = django.dispatch.Signal(providing_args=['element_name', 'request'])
-pre_metadata_element_update = django.dispatch.Signal(providing_args=['element_name', 'element_id' 'request'])
+pre_metadata_element_update = django.dispatch.Signal(providing_args=['element_name', 'element_id', 'request'])
+post_metadata_element_update = django.dispatch.Signal(providing_args=['element_name', 'element_id'])
 
 pre_download_file = django.dispatch.Signal(providing_args=['resource', 'download_file_name'])
 
diff --git a/hs_core/views/__init__.py b/hs_core/views/__init__.py
index e6e2de5f3..b6897198d 100755
--- a/hs_core/views/__init__.py
+++ b/hs_core/views/__init__.py
@@ -262,7 +262,15 @@ def update_metadata_element(request, shortkey, element_name, element_id, *args,
                 element_data_dict = response['element_data_dict']
                 try:
                     res.metadata.update_element(element_name, element_id, **element_data_dict)
+                    post_handler_response = post_metadata_element_update.send(sender=sender_resource, element_name=element_name, element_id=element_id)
                     is_update_success = True
+                    # this is how we handle if a post_metadata_element_update receiver
+                    # is not implemented in the resource type's receivers.py
+                    element_exists = True
+                    for receiver, response in post_handler_response:
+                        if 'element_exists' in response:
+                            element_exists = response['element_exists']
+
                 except ValidationError as exp:
                     err_msg = err_msg.format(element_name, exp.message)
                     request.session['validation_error'] = err_msg
@@ -293,10 +301,13 @@ def update_metadata_element(request, shortkey, element_name, element_id, *args,
                 ajax_response_data = {'status': 'success',
                                       'element_name': element_name,
                                       'spatial_coverage': spatial_coverage_dict,
-                                      'metadata_status': metadata_status}
+                                      'metadata_status': metadata_status,
+                                      'element_exists':element_exists}
             else:
-                ajax_response_data = {'status': 'success', 'element_name': element_name,
-                                      'metadata_status': metadata_status}
+                ajax_response_data = {'status': 'success',
+                                      'element_name': element_name,
+                                      'metadata_status': metadata_status,
+                                      'element_exists':element_exists}
 
             return JsonResponse(ajax_response_data)
         else:
diff --git a/hs_modflow_modelinstance/receivers.py b/hs_modflow_modelinstance/receivers.py
index 42c1062c8..c212ef542 100644
--- a/hs_modflow_modelinstance/receivers.py
+++ b/hs_modflow_modelinstance/receivers.py
@@ -1,32 +1,50 @@
 from django.dispatch import receiver
+from django.core.exceptions import ObjectDoesNotExist
 
 from hs_core.signals import pre_metadata_element_create, pre_metadata_element_update, \
-    pre_create_resource
+    pre_create_resource, post_metadata_element_update
+
+import hs_modflow_modelinstance.models as modflow_models
 
-from hs_modflow_modelinstance.models import MODFLOWModelInstanceResource
 from hs_modflow_modelinstance.forms import ModelOutputValidationForm, ExecutedByValidationForm,\
     StudyAreaValidationForm, GridDimensionsValidationForm, StressPeriodValidationForm,\
     GroundWaterFlowValidationForm, BoundaryConditionValidationForm, ModelCalibrationValidationForm,\
     ModelInputValidationForm, GeneralElementsValidationForm
 
 
-@receiver(pre_create_resource, sender=MODFLOWModelInstanceResource)
+@receiver(pre_create_resource, sender=modflow_models.MODFLOWModelInstanceResource)
 def modflowmodelinstance_pre_create_resource(sender, **kwargs):
     metadata = kwargs['metadata']
     modeloutput = {'modeloutput': {'includes_output': False}}
     metadata.append(modeloutput)
 
 
-@receiver(pre_metadata_element_create, sender=MODFLOWModelInstanceResource)
+@receiver(pre_metadata_element_create, sender=modflow_models.MODFLOWModelInstanceResource)
 def metadata_element_pre_create_handler(sender, **kwargs):
     return _process_metadata_update_create(update_or_create='create', **kwargs)
 
 
-@receiver(pre_metadata_element_update, sender=MODFLOWModelInstanceResource)
+@receiver(pre_metadata_element_update, sender=modflow_models.MODFLOWModelInstanceResource)
 def metadata_element_pre_update_handler(sender, **kwargs):
     return _process_metadata_update_create(update_or_create='update', **kwargs)
 
 
+@receiver(post_metadata_element_update, sender=modflow_models.MODFLOWModelInstanceResource)
+def check_element_exist(sender, **kwargs):
+    element_id = kwargs['element_id']
+    element_name = kwargs['element_name']
+    element_exists = False
+    class_names = vars(modflow_models)
+    for class_name, cls in class_names.iteritems():
+        if class_name.lower() == element_name.lower():
+            try:
+                cls.objects.get(pk=element_id)
+                element_exists = True
+            except ObjectDoesNotExist:
+                break
+    return {'element_exists': element_exists}
+
+
 def _process_metadata_update_create(update_or_create, **kwargs):
     element_name = kwargs['element_name'].lower()
     request = kwargs['request']
diff --git a/hs_modflow_modelinstance/templates/pages/modflowmodelinstanceresource.html b/hs_modflow_modelinstance/templates/pages/modflowmodelinstanceresource.html
index 6739ac2f2..7a93281b7 100644
--- a/hs_modflow_modelinstance/templates/pages/modflowmodelinstanceresource.html
+++ b/hs_modflow_modelinstance/templates/pages/modflowmodelinstanceresource.html
@@ -193,7 +193,7 @@
             <table class="custom-table">
                 <tbody>
                 <tr>
-                    {% if boundary_condition.specified_head_boundary_packages %}
+                    {% if boundary_condition.other_specified_head_boundary_packages or boundary_condition.get_specified_head_boundary_packages %}
                     <th class="text-muted">Specified head boundary package(s)</th>
                     <td>
                         {% if boundary_condition.other_specified_head_boundary_packages and boundary_condition.get_specified_head_boundary_packages %}
@@ -207,7 +207,7 @@
                     {% endif %}
                 </tr>
                 <tr>
-                    {% if boundary_condition.specified_flux_boundary_packages %}
+                    {% if boundary_condition.other_specified_flux_boundary_packages or boundary_condition.get_specified_flux_boundary_packages %}
                         <th class="text-muted">Specified flux boundary package(s)</th>
                     <td>
                         {% if boundary_condition.other_specified_flux_boundary_packages and boundary_condition.get_specified_flux_boundary_packages %}
@@ -221,7 +221,7 @@
                     {% endif %}
                 </tr>
                 <tr>
-                    {% if boundary_condition.head_dependent_flux_boundary_packages %}
+                    {% if boundary_condition.other_head_dependent_flux_boundary_packages or boundary_condition.get_head_dependent_flux_boundary_packages %}
                         <th class="text-muted">Head-dependent flux boundary package(s)</th>
                     <td>
                         {% if boundary_condition.other_head_dependent_flux_boundary_packages and boundary_condition.get_head_dependent_flux_boundary_packages %}
diff --git a/theme/static/js/resourceLandingAjax.js b/theme/static/js/resourceLandingAjax.js
index 1ff8c9fda..7329d1519 100644
--- a/theme/static/js/resourceLandingAjax.js
+++ b/theme/static/js/resourceLandingAjax.js
@@ -381,6 +381,12 @@ function metadata_update_ajax_submit(form_id){
                     update_url = "/hsapi/_internal/" + res_short_id + "/" + json_response.element_name +"/" + json_response.element_id + "/update-metadata/"
                     $form.attr('action', update_url);
                 }
+                if (json_response.element_exists == false){
+                    form_update_action = $form.attr('action');
+                    res_short_id = form_update_action.split('/')[3];
+                    update_url = "/hsapi/_internal/" + res_short_id + "/" + json_response.element_name + "/add-metadata/"
+                    $form.attr('action', update_url);
+                }
                 if (json_response.hasOwnProperty('element_name')){
                     if(json_response.element_name === 'title'){
                         $res_title = $(".section-header").find("span").first();
['hs_core/views/__init__.py', 'hs_modflow_modelinstance/receivers.py', 'hs_modflow_modelinstance/templates/pages/modflowmodelinstanceresource.html', 'theme/static/js/resourceLandingAjax.js', 'hs_core/signals.py']